package com.qili.controller.supervisor;


import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qili.annotation.Guide;
import com.qili.base.controller.BaseController;
import com.qili.base.entity.CurrentUser;
import com.qili.core.annotation.Log;
import com.qili.core.shiro.Principal;
import com.qili.core.utils.DictTypes;
import com.qili.core.utils.DictUtil;
import com.qili.core.utils.FileUtils;
import com.qili.entity.base.BaseCompany;
import com.qili.entity.base.BaseCompanyOwner;
import com.qili.entity.base.BaseDict;
import com.qili.entity.jc.JcPayRecord;
import com.qili.entity.jc.dto.JcPayRecordDTO;
import com.qili.entity.jc.dto.JcProjectDTO;
import com.qili.entity.jc.dto.JcProjectPayDTO;
import com.qili.entity.supervisor.*;
import com.qili.entity.supervisor.dto.*;
import com.qili.entity.supplier.SupplierProjectAccept;
import com.qili.entity.supplier.dto.ProjectPlaceDTO;
import com.qili.entity.supplier.dto.SupplierProjectDTO;
import com.qili.entity.sys.SysLog;
import com.qili.entity.sys.SysRegion;
import com.qili.entity.sys.SysUser;
import com.qili.entity.sys.dto.SysUserDTO;
import com.qili.entity.zx.ExProjectBigEvent;
import com.qili.exception.MyException;
import com.qili.mapper.sys.SysLogMapper;
import com.qili.redis.RedisService;
import com.qili.service.SysUserService;
import com.qili.service.affairCase.AffairCaseService;
import com.qili.service.base.*;
import com.qili.service.supervisor.*;
import com.qili.service.supplier.ProjectPlaceService;
import com.qili.service.supplier.SupplierProjectAcceptService;
import com.qili.service.supplier.SupplierProjectManagerService;
import com.qili.service.sys.SysRegionService;
import com.qili.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipOutputStream;

import static java.util.Objects.isNull;

@Controller
@Slf4j
@RequestMapping("/supervisor/projectManager")
public class SupervisorController extends BaseController {
    @Autowired
    private SupervisorProjectService supervisorProjectService;
    @Autowired
    private DataSourceTransactionManager manager;
    @Autowired
    BaseDictService baseDictService;
    @Autowired
    SysRegionService sysRegionService;

    @Autowired
    SupervisorFileService supervisorFileService;

    @Autowired
    SupervisorProjectStageService supervisorProjectStageService;
    @Autowired
    SupervisorProjectMilepostService supervisorProjectMilepostService;

    @Autowired
    UploadUtil uploadUtil;

    @Autowired
    ProjectContractService projectContractService;
    @Autowired
    ProjectLeaderService projectLeaderService;
    @Autowired
    ProjectUnitConstructionService projectUnitConstructionService;
    @Autowired
    ProjectTypeService projectTypeService;
    @Autowired
    BaseStageService baseStageService;
    @Autowired
    BaseMilepostService baseMilepostService;
    @Autowired
    SupervisorProjectFormsService supervisorProjectFormsService;
    @Autowired
    SupervisorProjectPayService supervisorProjectPayService;
    @Autowired
    SupervisorProjectFormsDataService supervisorProjectFormsDataService;
    @Autowired
    SysUserService sysUserService;
    @Autowired
    BaseCompanyService baseCompanyService;
    @Autowired
    BaseCompanyOwnerService baseCompanyOwnerService;
    @Autowired
    ProjectAdminService projectAdminService;
    @Autowired
    SupervisorPayRecordService supervisorPayRecordService;
    @Autowired
    ProjectBigEventService projectBigEventService;
    @Autowired
    ProjectSealRecordService projectSealRecordService;

    @Autowired
    SupplierProjectManagerService supplierProjectManagerService;
    @Autowired
    SupplierProjectAcceptService supplierProjectAcceptService;
    @Autowired
    ProjectPlaceService projectPlaceService;

    @Autowired
    private RedisService redisService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    SysUserService userService;


    @Autowired
    AffairCaseService affairCaseService;


    @Value("${supervisor.downloadPath}")
    private String uploadPath;
    @Value("${supervisor.tempPath}")
    private String tempPath;

    @Autowired
    SysLogMapper sysLogMapper;

    /**
     * 监理服务首页
     *
     * @return
     */
    @GetMapping(value = "index")
    @RequiresPermissions("jx:index")
    public String index(HttpServletRequest request) {
        CurrentUser currentUser = CommonUtil.getUser();
        String userId = CommonUtil.getUserId();
        SysUser sysUser = sysUserService.selectByPrimaryKey(userId);
        if(sysUser==null){
            // 跳转到登陆页面
            request.setAttribute("type","login");
            return "/login";
        }
        // 个人中心设置的数量
        String tagnum = sysUser.getNumTag();
        currentUser.setNumTag(tagnum);
        String AsTags = currentUser.getTags();
        String[] AyTags;
        int count=0;
        if (StringUtil.isNotBlank(AsTags) && StringUtil.isNotBlank(tagnum)) {
            String[] newAyTags = new String[Integer.valueOf(tagnum)];
            AyTags = AsTags.split(";");
            String strname="";
            for (int k=0;k<AyTags.length;k++){
               String str= AyTags[k];
                String[] split = str.split(":");
                if(split!=null){
                    if(split.length>0){
                       String projectId= split[0];
                       if(StringUtil.isNotBlank(projectId)){
                           SupervisorProject project=supervisorProjectService.selectByPrimaryKey(projectId);
                           if(project!=null){
                               String status = project.getStatus();
                               if("000".equals(status)){
                                   //已经删除回收站的 清空session
                                   String projectName = project.getProjectName();
                                   strname=projectId+":"+projectName+";";
                                   AsTags=AsTags.replace(strname,"");
                                   count++;
                               }
                           }
                       }

                    }
                }
                sysUser.setTags(AsTags);
                userService.updateTags(sysUser);
                currentUser.setTags(AsTags);
                Session session = com.qili.core.shiro.Principal.getSession();
                session.setAttribute("currentPrincipal", currentUser);
            }

            int length = AyTags.length;
            if (Integer.valueOf(tagnum) < length) {
                //清除多余的0
                for (int i = 0; i < length; i++) {
                    if (i < Integer.valueOf(tagnum)) {
                        newAyTags[i] = AyTags[i];
                    }
                }
                currentUser.setTags(StringUtils.join(newAyTags, ";") + ";");
            }
        }
        // 2021 0820 已经删除的项目 不能在显示
        Session session = com.qili.core.shiro.Principal.getSession();
        session.setAttribute("currentPrincipal", currentUser);
        SupervisorFile supervisorFile = supervisorFileService.getPersonalImg(userId);
        request.setAttribute("file", supervisorFile);
        return "/supervisor/index/index";
    }

    /**
     *
     * @param temp
     * @return
     */
    @GetMapping(value = "isParamSys")
    @ResponseBody
    public String isParamSys(String temp){
        // 变量存的是 id:项目名称   d48e6b86cfd84a9aa6870694ff03c2df:撒打算打算
        String[] tempAsTags;
        if (StringUtil.isNotBlank(temp)){
            tempAsTags = temp.split(";");
            String strname="";
            for (int j = 0;j < tempAsTags.length;j++){
                String str= tempAsTags[j];
                String[] split = str.split(":");
                if(split != null && split.length > 0){
                    // 当前id
                    String projectId= split[0];
                    if(StringUtil.isNotBlank(projectId)){
                        SupervisorProject project=supervisorProjectService.selectByPrimaryKey(projectId);
                        if (project == null){
                            String projectName = split[1];
                            strname=projectId+":"+projectName+";";
                            temp = temp.replace(strname,"");
                        }
                    }
                }
            }
        }
        return temp;
    }
    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:项目管理
     * @Date:13:23 2020/11/26
     */
    @GetMapping("projectIndex")
    @RequiresPermissions("sr:mgr")
    public String managerIndex(Model model, HttpServletRequest request) {
        // 获取单位性质
        List<BaseDict> prostatus = DictUtil.getDictByType(DictTypes.UNIT_NATURE);

        List<BaseDict> hystatus = DictUtil.getDictByType(DictTypes.INDUSTRY);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        // 市
        List<SysRegion> citylist = sysRegionService.selectListByLevelId("2");
        //所属公司
        List<BaseCompanyOwner> ownerCompanyList = baseCompanyOwnerService.selectAll();
        model.addAttribute("ownerCompanyList", ownerCompanyList);
        model.addAttribute("provincelist", provincelist);
        model.addAttribute("citylist", citylist);
        model.addAttribute("prostatus", prostatus);
        model.addAttribute("hystatus", hystatus);
        // 工程经理也有  修改记录的权限
        Subject subject = SecurityUtils.getSubject();
        if (subject.hasRole("gcbjl")){
            request.setAttribute("gcbjl","1");
        }
        return "/supervisor/projectManager/index";

    }

    /**
     * @param
     * @Author:zhaoyongke
     * @Description:项目管理----回收站 显示
     * @Date:13:23 2020/11/26
     */
    @GetMapping(value = "viewHs")
    public String viewHs() {
        return "/supervisor/projectManager/viewHs";
    }

    /**
     * @param
     * @Author:zhaoyongke
     * @Description: 项目创建账号信息查询
     * @Date:22:21 2020/12/14
     */
    @GetMapping(value = "viewAc")
    public String viewAc(Model model, HttpServletRequest request) {
        String projectId = request.getParameter("projectId");
        model.addAttribute("projectId", projectId);
        return "/supervisor/projectManager/viewAc";
    }

    /**
     * @param
     * @Author:zhaoyongke
     * @Description: 表单文件添加
     * @Date:9:29 2020/11/30
     */
    @GetMapping(value = "addForm")
    public String addForm(SupervisorProjectDTO dto, HttpServletRequest request, Model model) throws Exception {
        String type = dto.getType();// 文件類型
        String spf_prjid = dto.getId();// 項目id
        String spf_staid = dto.getStageId();// 阶段id
        String spf_milid = dto.getSpmId();// 里程id
        String fbCode = dto.getFbCode();// 分包
        String pcId = dto.getFbId();// 分包Id
        String fileId = dto.getFileId();// 文件表id  个别form 添加是针对某个文档操作 需要知道具体是哪个文件 fileId
        /*承建单位不能上传监理文档*/

        String role = sysUserService.getUserRole(spf_prjid);
        if ("xmjl".equals(role) || "cj".equals(role) || "zjlgcs".equals(role) || "jlgcs".equals(role)) {
            if ("cj".equals(role)) {
                BaseDict wjdict = DictUtil.getDictByCode(DictTypes.WJ, type);
                String level11 = wjdict.getBadtLevel11();
                if (level11.indexOf("cj") < 0) {
                    request.setAttribute("message", "您没有权限操作");
                    return "/error/lcerror";
                }
            }
            if ("xmjl".equals(role)) {
                if ("111".equals(type)) {
                    /*监理通知回执单*/
                    request.setAttribute("message", "您没有权限操作");
                    return "/error/lcerror";

                }

            }

        } else {
            request.setAttribute("message", "您没有权限操作");
            return "/error/lcerror";
        }


        if (StringUtil.isNotBlank(pcId)) {
            Boolean ischeck = checkFbCj(pcId, spf_prjid);
            if (!ischeck) {
                request.setAttribute("message", "该分包没有承建单位，不能上传文件");
                return "/error/lcerror";
            }
        }
        //查询项目详情
        SupervisorProjectDTO supervisorProjectdto = getSupervisorProjectDTO(spf_prjid);
        supervisorProjectdto.setFileId(fileId);
        // 获得文档流水号
        String orderCode = getFileOrderCode(spf_prjid, spf_staid, spf_milid, pcId, type);
        // 获取跳转路径
        String re_url = getUrl(type, model);
        //特殊处理
        doSomeSpecialSthing(model, type, spf_prjid, fbCode, supervisorProjectdto, orderCode);
        //解析文件数据
        parsingFileDataToList(model, type, fileId, spf_prjid, pcId);
        model.addAttribute("ind", Integer.valueOf(orderCode));
        model.addAttribute("pdto", supervisorProjectdto);
        model.addAttribute("spf_prjid", spf_prjid);
        model.addAttribute("spf_staid", spf_staid);
        model.addAttribute("spf_milid", spf_milid);
        model.addAttribute("spfFilecode", type);// 文件类型编号
        model.addAttribute("fbCode", fbCode);// 分包编号
        model.addAttribute("pcId", pcId);// 分包编号
        model.addAttribute("fileId", fileId);// 文件表id
        return re_url;
    }

    /**
     * @param spf_prjid
     * @Description:获取SupervisorProject
     * @Author:Zhangshuo
     * @Date:11:20 2020-12-19
     */
    private SupervisorProjectDTO getSupervisorProjectDTO(String spf_prjid) {
        SupervisorProjectDTO supervisorProjectdto = new SupervisorProjectDTO();
        //查询项目
        supervisorProjectdto.setId(spf_prjid);
        List<SupervisorProjectDTO> projectlist = supervisorProjectService.selectSupervisorProject(supervisorProjectdto);
        if (projectlist.size() > 0) {
            supervisorProjectdto = projectlist.get(0);
        }
        String names = "";
        String secondSupervisorEngineer = supervisorProjectdto.getSecondSupervisorEngineer();
        if (StringUtil.isNotBlank(secondSupervisorEngineer)) {
            String[] str = supervisorProjectdto.getSecondSupervisorEngineer().split(",");
            for (int x = 0; x < str.length; x++) {
                String name = sysUserService.selectByPrimaryKey(str[x]).getRealName();
                if (x == 0) {
                    names = name;
                } else {
                    names = names + "," + name;
                }
            }
            supervisorProjectdto.setSecondSupervisorEngineerName(names);
        }

        return supervisorProjectdto;
    }

    /**
     * @param model
     * @param type
     * @param spf_prjid
     * @param fbCode
     * @param supervisorProjectdto
     * @param orderCode
     * @Description:特殊处理
     * @Author:Zhangshuo
     * @Date:11:19 2020-12-19
     */
    private void doSomeSpecialSthing(Model model, String type, String spf_prjid, String fbCode, SupervisorProjectDTO supervisorProjectdto, String orderCode) {

        ProjectUnitConstructionDTO unitConstructiondto = new ProjectUnitConstructionDTO();
        unitConstructiondto.setSupervisorProjectId(spf_prjid);
        if ("039".equals(type) || "016".equals(type) || "036".equals(type) || "037".equals(type)  || "040".equals(type)  || "042".equals(type)  || "045".equals(type)) {
            /*材料进场检验报告*/
            unitConstructiondto.setConstructionSubContractNumber(fbCode);
        }

        if (com.qili.core.shiro.Principal.hasRole("nupm")) {
            //承建单位
            unitConstructiondto.setProjectManager(CommonUtil.getUserId());
        }
        if ("111".equals(type)) {
            /*监理通知回执单 需要查询监理通知选择的承建单位*/
            String fileId = supervisorProjectdto.getFileId();
            SupervisorFile fileparent = supervisorFileService.selectByPrimaryKey(fileId);
            String linkId = fileparent.getLinkId() + "";
            if (StringUtil.isNotBlank(linkId)) {
                SupervisorProjectForms form = supervisorProjectFormsService.selectByPrimaryKey(linkId);
                /*承建单位项目经理*/
                String cjManagerUserId = form.getSpfF30() + "";
                if (StringUtil.isNotBlank(cjManagerUserId)) {
                    unitConstructiondto.setProjectManager(cjManagerUserId);
                }
                String parentordercode = "JLTZ-" + form.getOrderCode();
                model.addAttribute("parentordercode", parentordercode);
            }


        }
        List<ProjectUnitConstructionDTO> listcjlist = projectUnitConstructionService.selectProjectUnitList(unitConstructiondto);
        //承建单位名称
        ArrayList<String> AlstCjdwstr = new ArrayList<>();
        //承建合同名称
        ArrayList<String> AlstCjHtstr = new ArrayList<>();
        for (int i = 0; i < listcjlist.size(); i++) {
            AlstCjdwstr.add(listcjlist.get(i).getUnitConstruction());
            // 承建合同名称
            AlstCjHtstr.add(listcjlist.get(i).getConstructionContract());
        }
        String cj = AlstCjdwstr.toString();
        String cjstr = "";
        if (StringUtil.isNotBlank(cj)) {
            //截取前后【】
            cjstr = cj.replaceAll("\\[", "").replaceAll("\\]", "");
        }
        String cjht = AlstCjHtstr.toString();
        String cjhtstr = "";
        if (StringUtil.isNotBlank(cjht)) {
            //截取前后【】
            cjhtstr = cjht.replaceAll("\\[", "").replaceAll("\\]", "");
        }
        model.addAttribute("cj", cjstr);
        model.addAttribute("cjht", cjhtstr);
        if ("080".equals(type) || "060".equals(type) || "054".equals(type)) {
            // 监理 工作总结报告  查询统计文档列表
            getFileTypeCountList(model, spf_prjid);
            //获取项目分包及建设内容
            getProjectUnitInfor(model, supervisorProjectdto, listcjlist);
        }
        if (type.equals("039")) {
            /*材料设备进场检验报告*/
            orderCode = "-" + fbCode + "-" + orderCode;
        } else if (type.equals("040") || type.equals("041")) {
            /*设备开箱检验报告 设备加电检测记录表*/
            //获取材料进场检验报告的序号
            String fileId = supervisorProjectdto.getFileId();
            SupervisorFile file = supervisorFileService.selectByPrimaryKey(fileId);
            String lnkid = file.getLinkId();
            SupervisorProjectForms from = supervisorProjectFormsService.selectByPrimaryKey(lnkid);
            orderCode = from.getOrderCode();
        }
        // 文件类型编号
        model.addAttribute("orderCode", orderCode);
        model.addAttribute("listcjlist", listcjlist);
        //到货验收报告
        if(listcjlist!=null){
            if(listcjlist.size()>0){
                ProjectUnitConstructionDTO unitConstructionDTO = listcjlist.get(0);
                model.addAttribute("cjdto", unitConstructionDTO);
            }

        }

    }

    /**
     * @param model
     * @param spf_prjid
     * @Description:
     * @Author:Zhangshuo
     * @Date:11:22 2020-12-19
     */
    private void getFileTypeCountList(Model model, String spf_prjid) {
        SupervisorFileDTO filedto = new SupervisorFileDTO();
        filedto.setProjectId(spf_prjid);
        List<SupervisorFileDTO> wjList = supervisorFileService.getFileCountByType(filedto);
        model.addAttribute("wjList", wjList);//
        Integer count = 0;
        for (int i = 0; i < wjList.size(); i++) {
            count = count + wjList.get(i).getCount();
        }
        model.addAttribute("count", count);//
    }

    /**
     * @param model
     * @param supervisorProjectdto
     * @param listcjlist
     * @Description:
     * @Author:Zhangshuo
     * @Date:11:22 2020-12-19
     */
    private void getProjectUnitInfor(Model model, SupervisorProjectDTO supervisorProjectdto, List<ProjectUnitConstructionDTO> listcjlist) {
        StringBuilder AsbFbText = new StringBuilder();
        AsbFbText.append(supervisorProjectdto.getProjectName() + "（项目名称）");
        AsbFbText.append("包含 " + (listcjlist.size()) + "个子项目，分别是");
        StringBuilder AsbItems = new StringBuilder();
        StringBuffer pjText = new StringBuffer();
        int y = 1;
        for (int i = 0; i < listcjlist.size(); i++) {
            ProjectUnitConstruction AoTmp = listcjlist.get(i);
            AsbFbText.append("《" + AoTmp.getConstructionContract() + "》（包号为" + AoTmp.getConstructionSubContractNumber() + "）、");
            AsbItems.append("《" + AoTmp.getConstructionContract() + "》合同（合同编号为" + AoTmp.getContractNo() + "）由" + AoTmp.getUnitConstruction() + "（承建单位）承担，主要建设内容包括***等。");
            pjText.append("" + (i + 1) + "、《" + AoTmp.getConstructionContract() + "（" + (i + 1) + "子项目名称）》合同（合同编号为" + AoTmp.getContractNo() + "）于****年**月**日完成到货验收，于****年**月**日完成三方检查检验，于****年**月**日完成项目初验。");
            y++;
        }
        AsbFbText.append(AsbItems.toString());
        model.addAttribute("prjcontent", AsbFbText.toString());
        model.addAttribute("pjtext", pjText.append("" + y + "、系统资料齐全,能够满足项目管理和维护需要。" + (y + 1) + "、在监理工作的基础上和经过多次对建设内容的核对，监理方经过研究认为" + supervisorProjectdto.getProjectName() + "可以进行验收"));

        /*1、《***（1子项目名称）》合同（合同编号为***）于****年**月**日完成到货验收，于****年**月**日完成三方检查检验，于****年**月**日完成项目初验。
        2、《***（2子项目名称）》合同（合同编号为***）于****年**月**日完成到货验收，于****年**月**日完成三方检查检验，于****年**月**日完成项目初验。
        3、系统资料齐全,能够满足项目管理和维护需要。4、在监理工作的基础上和经过多次对建设内容的核对，监理方经过研究认为该******可以进行验收。*/
        //**项目（项目名称）包含 **个子项目，
        //分别是
        //《***（1 子项目名称）》（包号）、
        //《***（2 子项目名称）》（包号）。
        //
        //
        //《***（1 子项目名称）》合同（合同编号为 ***）由 **（承建单位）承担，主要建设内容包括 ***等。
        //《***（2 子项目名称）》合同（合同编号为 ***）由 **（承建单位）承担，主要建设内容包括 ***等。
    }


    /**
     * @param model
     * @param type
     * @param fileId
     * @Author:Zhangshuo
     * @Description:解析Word文件到List
     * @Date:14:04 2020-12-10
     */
    private void parsingFileDataToList(Model model, String type, String fileId, String pPrjId, String pPkgId) throws Exception {
        switch (type) {
            case "039"://材料检验
                //获取合同比对报告文件地址
                SupervisorFile supervisorFile = new SupervisorFile();
                supervisorFile.setProjectId(pPrjId);
                supervisorFile.setPcId(pPkgId);
                supervisorFile.setType("044");
                int AiCnt = supervisorFileService.selectCount(supervisorFile);
                if (AiCnt == 1) {
                    supervisorFile = supervisorFileService.selectOne(supervisorFile);
                    String AsSaveContactPath = supervisorFile.getUrl();
                    // 读取合同对比报告中的数据
                    List<List<String>> AlstWordData = null;
                    try {
                        AlstWordData = WordUtil.getWordTableData(AsSaveContactPath, 1, 6);
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw  new  Exception("文件解析异常，请按照模板文件");
                    }

                    // 已经全部进场的 不需要在显示  根据 合同对比报告中的 实际数量和清单数量的值 对比
                    List<List<String>> dataAdd =new ArrayList<>();
                    try {
                        if(AlstWordData!=null ){
                            if(AlstWordData.size()>0){
                                for (int i = 0; i <AlstWordData.size() ; i++) {
                                    List<String> strings = AlstWordData.get(i);
                                    int size = strings.size();
                                    if(strings!=null){
                                        if(strings.size()>2){
                                            // 清单数量
                                            String snum = strings.get(5)+"";
                                            // 进场数量
                                            String sjnum = strings.get(7)+"";
                                            if(StringUtil.isNumeric(snum)   &&   StringUtil.isNumeric(sjnum) ){
                                                BigDecimal sDouble = new BigDecimal(snum);
                                                BigDecimal sjDouble = new BigDecimal(sjnum);
                                                if(sjDouble.compareTo(sDouble)>0  || sjDouble.compareTo(sDouble)==0  ){

                                                }else{
                                                    dataAdd.add(strings);
                                                }
                                            }else{
                                                dataAdd.add(strings);
                                            }
                                        }

                                    }


                                }
                            }

                        }
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }

                    model.addAttribute("htlist", dataAdd);
                    model.addAttribute("htlistJson", JSONArray.toJSONString(dataAdd));
                } else if (AiCnt == 0) {
                    throw new Exception("非常抱歉，项目ID:" + pPrjId + "的项目未发现合同比对报告，无法进行合同比对。");
                } else if (AiCnt > 1) {
                    throw new Exception("非常抱歉，项目ID:" + pPrjId + "的项目发现多个合同比对报告，仅支持一个合同进行比对，请删除对于的合同对比报告。");
                }
                break;
            case "040"://开箱检验
            case "041"://加电检测
                // 查询文件
                SupervisorFile file = new SupervisorFile();
                file.setId(fileId);
                file = supervisorFileService.selectByPrimaryKey(file);
                String AsFilePath = file.getUrl();
                List<List<String>> AlstFileTableData = null;
                if (StringUtil.isNotBlank(AsFilePath)) {
                    //读取word中表格数据
                    try {
                        AlstFileTableData = WordUtil.getWordTableData(file.getUrl(), 1, 6);
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw  new  Exception("文件解析异常，请按照模板文件");
                    }
                }
                if(AlstFileTableData!=null){
                    if(AlstFileTableData.size()>0){
                        for (int j = 0; j <AlstFileTableData.size() ; j++) {
                            String str = AlstFileTableData.get(j)+"";
                            if(StringUtil.isNotBlank(str)){
                                if(str.indexOf("单位代表")>0){
                                    AlstFileTableData.remove(j);
                                }
                            }
                        }
                    }

                }




                model.addAttribute("devlist", AlstFileTableData);
                break;
        }
    }

    /**
     * @param type
     * @param model
     * @Author:zhaoyongke
     * @Description:根据type 获取路径
     * @Date:17:06 2020/12/1
     */
    public String getUrl(String type, Model model) {
        String re_url = "";
        switch (type) {
            case "009":
                // 项目印章使用授权书
                /*项目印章*/
                /*                List<BaseDict> xmzlist = DictUtil.getDictByType(DictTypes.JLZ);*/

                // 获取个人中心的图片
                String imageurl = "";
                String userId = CommonUtil.getUserId();
                SupervisorFile file = new SupervisorFile();
                file.setProjectId(userId);
                file.setType("202");
                SupervisorFile supervisorFile = supervisorFileService.selectOne(file);
                if (supervisorFile != null) {
                    imageurl = supervisorFile.getUrl();
                }
                //  if (StringUtil.isBlank(imageurl)) {
                // model.addAttribute("message", "请在个人中心上传签章图片");
                //  re_url = "/error/lcerror";

                // } else {
                String qzimage = "";
//                    String qzimage = File.separator + "userfile" + (imageurl.substring((uploadUtil.getUploadPath() + uploadUtil.getUserPath()).length()));
//                    model.addAttribute("qzimage", qzimage);
//                    model.addAttribute("qzimageurl", imageurl);
                //20210810 修改  查询后台维护的签章
                SupervisorFile fileSeal = new SupervisorFile();
                fileSeal.setType("118");
                List<SupervisorFile> listqzlist = supervisorFileService.select(fileSeal);
                for (int i = 0; i < listqzlist.size(); i++) {
                    imageurl = listqzlist.get(i).getUrl();
                    qzimage = File.separator + "img" + (imageurl.substring((uploadUtil.getUploadPath() + uploadUtil.getPersonPath()).length()));
                    listqzlist.get(i).setLinkId(listqzlist.get(i).getUrl());
                    listqzlist.get(i).setUrl(qzimage);
                }
                model.addAttribute("listqzlist", listqzlist);
                re_url = "/supervisor/projectManager/schy-xmyzsq-form";
                //}
                break;
            case "010":
                // 会议纪要
                model.addAttribute("wjNum", "41");
                re_url = "/supervisor/projectManager/schy-hyjy-form";
                break;
            case "016":
                // 开工通知
                re_url = "/supervisor/projectManager/kg-kgtz-form";
                break;
            case "021":
                // 监理审核报告
                model.addAttribute("wjNum", "61");
                re_url = "/supervisor/projectManager/jhfan-jlshbg-form";
                break;
            case "027":
                // 监理审核报告(文档审核报告)
                model.addAttribute("wjNum", "51");
                re_url = "/supervisor/projectManager/jhfan-jlshbg-form";
                break;
            case "031":
                // 监理审核报告(文档审核报告)
                model.addAttribute("wjNum", "41");
                re_url = "/supervisor/projectManager/jhfan-jlshbg-form";
                break;
            case "035":
                // 监理审核报告(文档审核报告)
                model.addAttribute("wjNum", "41");
                re_url = "/supervisor/projectManager/jhfan-jlshbg-form";
                break;
            case "036":
                // 检查记录
                model.addAttribute("wjNum", "11");
                re_url = "/supervisor/projectManager/ss-jcpz-jcjl-form";
                break;
            case "037":
                // 旁站记录
                re_url = "/supervisor/projectManager/ss-jcpz-pzjl-form";
                break;
            case "039":
                // 到货验收---材料设备进场检验报告
                re_url = "/supervisor/projectManager/dhys-cljcjy-form";
                break;
            case "040":
                // 设备开箱检验报告
                re_url = "/supervisor/projectManager/dhys-kxjy-form";
                break;
            case "041":
                // 设备加电检验报告
                re_url = "/supervisor/projectManager/dhys-jdjy-form";
                break;
            case "042":
                // 序列号验证记录
                re_url = "/supervisor/projectManager/dhys-xlhyzjl-form";
                break;
            case "045":
                // 到货验收--到货验收报告
                re_url = "/supervisor/projectManager/dhys-dhysbg-form";
                break;
            case "053":
                // 初验  ---文档审核报告
                model.addAttribute("wjNum", "21");
                re_url = "/supervisor/projectManager/jhfan-jlwdshbg-form";
                break;
            case "054":
                // 验收阶段---初验----监理工作总结报告
                model.addAttribute("wjNum", "31");
                re_url = "/supervisor/projectManager/ys-zjbg-form";
                break;
            case "055":
                // 初验--验收报告
                model.addAttribute("cy", "初验");
                model.addAttribute("wjNum", "41");
                re_url = "/supervisor/projectManager/ys-ysbg-form";
                break;
            case "060":
                // 验收阶段---终验----监理工作总结报告
                model.addAttribute("wjNum", "21");
                re_url = "/supervisor/projectManager/ys-zjbg-form";
                break;
            case "061":
                // 终验--验收报告
                model.addAttribute("cy", "终验");
                model.addAttribute("wjNum", "31");
                re_url = "/supervisor/projectManager/ys-ysbg-form";
                break;
            case "063":
                // 监理移交
                model.addAttribute("wjNum", "21");
                re_url = "/supervisor/projectManager/transfer-form";
                break;
            case "071":
                // 实施阶段--计划和方案---监理审核报告
                model.addAttribute("wjNum", "51");
                re_url = "/supervisor/projectManager/jhfan-jlshbg-form";
                break;
            case "075":
                // 初验--会议纪要
                model.addAttribute("wjNum", "51");
                re_url = "/supervisor/projectManager/schy-hyjy-form";
                break;
            case "076":
                // 终验--会议纪要
                model.addAttribute("wjNum", "41");
                re_url = "/supervisor/projectManager/schy-hyjy-form";
                break;
            case "079":
                // 验收阶段---验收----文档审核报告
                model.addAttribute("wjNum", "31");
                re_url = "/supervisor/projectManager/jhfan-jlwdshbg-form";
                break;
            case "080":
                // 验收阶段---验收----监理工作总结报告
                model.addAttribute("wjNum", "41");
                re_url = "/supervisor/projectManager/ys-zjbg-form";
                break;
            case "081":
                // 验收阶段---验收----验收报告
                model.addAttribute("wjNum", "51");
                re_url = "/supervisor/projectManager/ys-ysbg-form";
                break;
            case "082":
                // 验收阶段---验收---会议纪要
                model.addAttribute("wjNum", "61");
                re_url = "/supervisor/projectManager/schy-hyjy-form";
                break;
            case "084":
                // 其他阶段---项目会议---会议纪要
                model.addAttribute("wjNum", "11");
                re_url = "/supervisor/projectManager/schy-hyjy-form";
                break;
            case "086":
                // 其他监理工作--监理周报
                re_url = "/supervisor/projectManager/qt-jlzb-jlzb-form";
                break;
            case "089":
                // 其他监理工作--工程款支付--支付意见
                model.addAttribute("wjNum", "31");
                re_url = "/supervisor/projectManager/qt-gcpay-zfyj-form";
                break;
            case "090":
                // 其他监理工作--监理工作联系单
                re_url = "/supervisor/projectManager/qt-gzlxd-gzlxd-form";
                break;
            case "091":
                // 其他监理工作--监理通知
                re_url = "/supervisor/projectManager/qt-jltz-jltz-form";
                break;
            case "092":
                // 其他监理工作--专项报告
                re_url = "/supervisor/projectManager/qt-zxbg-zxbg-form";
                break;
            case "094":
                // 其他监理工作--变更处理---变更审核报告
                re_url = "/supervisor/projectManager/qt-bgcl-bgshbg-form";
                break;
            case "098":
                // 其他文件---工程备忘表
                re_url = "/supervisor/projectManager/qt-gcbw-gcbwb-form";
                break;
            case "100":
                // 其他文件---监理日志form
                re_url = "/supervisor/projectManager/qt-otherwj-jlrz-form";
                break;
            case "101":
                // 其他文件---监理月报form
                re_url = "/supervisor/projectManager/qt-otherwj-jlyb-form";
                break;
            case "106":
                // 实施阶段--检查评审-检查记录form
                model.addAttribute("wjNum", "11");
                re_url = "/supervisor/projectManager/ss-jcpz-jcjl-form";
                break;
            case "107":
                // 实施阶段---检查评审----文档审核报告
                model.addAttribute("wjNum", "21");
                re_url = "/supervisor/projectManager/jhfan-jlwdshbg-form";
                break;
            case "110":
                // 验收阶段--工程款支付--支付意见
                model.addAttribute("wjNum", "31");
                re_url = "/supervisor/projectManager/qt-gcpay-zfyj-form";
                break;
            case "111":
                // 监理通知 回执单
                re_url = "/supervisor/projectManager/qt-jltz-hzd-form";
                break;

            default:

        }
        return re_url;
    }

    /**
     * @param supervisorProjectFromsDTO
     * @Author:zhaoyongke
     * @Description: 表单保存文件
     * @Date:13:06 2020/11/30
     */
    @RequestMapping(value = "/addFormFile", method = RequestMethod.POST)
    @ResponseBody
    public JsonUtil addFormFile(SupervisorProjectFromsDTO supervisorProjectFromsDTO) {
        JsonUtil re = new JsonUtil();
        JSONObject jsonObject = new JSONObject();
        try {
            //文件保存路径
            String AsFilePath = prepareFormSavePath(-1, supervisorProjectFromsDTO);

            //获取Form实例
            SupervisorProjectForms AoForms = getSupervisorProjectForms(supervisorProjectFromsDTO, AsFilePath);
            AoForms.setCreateDate(DateUtil.getCurrentDateString());
            supervisorProjectFormsService.insertSelective(AoForms);
            //针对个别表格数据  把表格数据保存到 form-data 表中 比如 加电检验记录表
            ArrayList<SupervisorProjectFormsData> AlstFormData = supervisorProjectFromsDTO.getFormDataList();
            if (!isNull(AlstFormData)) {
                addFormData(AlstFormData, AoForms.getSpfId());
            }
            re.setFlag(true);
            re.setMsg("操作成功");
            //FormID
            jsonObject.put("spfId", AoForms.getSpfId());
            //PatchConfig ID
            jsonObject.put("fpid", supervisorProjectFromsDTO.getBfcId());
            re.setData(jsonObject);
        } catch (Exception e) {
            re.setMsg("操作失败" + e.getMessage());
            re.setFlag(false);
            e.printStackTrace();
        }
        return re;
    }

    /**
     * @Author:zhaoyongke
     * @Description: 针对表单存在表格得情况  插入 form-data
     * @Date:11:55 2020/12/5
     */
    public void addFormData(List<SupervisorProjectFormsData> plstFormData, String formid) {
        for (int i = 0; i < plstFormData.size(); i++) {
            SupervisorProjectFormsData formsData = plstFormData.get(i);
            formsData.setSpfId(formid);
            supervisorProjectFormsDataService.insertSelective(formsData);
        }
    }

    /**
     * @param poSupervisorProjectFromsDTO
     * @Author:Zhangshuo
     * @Description:
     * @Date:10:29 2020/12/4
     */
    private String prepareFormSavePath(int piFileCount, SupervisorProjectFromsDTO poSupervisorProjectFromsDTO) {
        // 准备上传参数
        String AsPrjName = poSupervisorProjectFromsDTO.getProjectName();
        String AsFileType = poSupervisorProjectFromsDTO.getSpfFilecode();
        String AsFbCode = poSupervisorProjectFromsDTO.getFbCode();
        String AsFpId = poSupervisorProjectFromsDTO.getBfcId();
        SupervisorFile AoSupervisorFile = getSupervisorFile(poSupervisorProjectFromsDTO);
        AoSupervisorFile.setType(AsFileType);

        String AsFileStuffix = ".doc";
        UploadType uploadType = prepareUploadType(0, AsPrjName, AsFileType, AsFbCode, AsFpId, AsFileStuffix, piFileCount, AoSupervisorFile, "", "");
        poSupervisorProjectFromsDTO.setFileInd(uploadType.getInd());
        String AsFilePath = FilePathUtil.getFullSavePathAndNameByConfigFileId(uploadType);
        return AsFilePath;
    }

    /**
     * @param supervisorProjectFromsDTO
     * @param psFilePath
     * @Author:Zhangshuo
     * @Description:
     * @Date:10:20 2020/12/4
     */
    private SupervisorProjectForms getSupervisorProjectForms(SupervisorProjectFromsDTO supervisorProjectFromsDTO, String psFilePath) {
        SupervisorProjectForms form = new SupervisorProjectForms();
        BeanUtil.copyNotNullBean(supervisorProjectFromsDTO, form);
        form.setSaveFilePath(psFilePath);
        form.setSpfId(IdUtil.simpleUUID());
        return form;
    }

    /**
     * @param type             上传类型 UploadType EnumByType
     * @param psPrjName        项目名称
     * @param psFileType       文件类型
     * @param psFbCode         分包编号
     * @param psFpId           路径配置表ID
     * @param poSupervisorFile
     * @Author:Zhangshuo
     * @Description:获取上传UploadType
     * @Date:10:03 2020/12/4
     */
    public UploadType prepareUploadType(int type, String psPrjName, String psFileType, String psFbCode, String psFpId, String psFileStuffix, int piFileCount, SupervisorFile poSupervisorFile, String pUploadType, String pPositionName) {
        // 获取文件名称
        String AsFileName = FileUtils.getFileName(psPrjName, psFileType, psFbCode, psFileStuffix, piFileCount, poSupervisorFile, pUploadType, pPositionName);
        // 替换项目名称
        ArrayList<String> placeHolder = new ArrayList<String>();
        placeHolder.add(psPrjName);
        placeHolder.add(psFbCode);
        placeHolder.add(pPositionName);
        UploadType uploadType = UploadType.getEnumByType(type);
        uploadType.setFileName(AsFileName);
        uploadType.setFilePathId(psFpId);
        uploadType.setPlaceholder(placeHolder);
        uploadType.setInd(poSupervisorFile.getInd());
        return uploadType;
    }

    /**
     * @param poSupervisorProjectFromsDTO
     * @Author:Zhangshuo
     * @Description:
     * @Date:9:31 2020/12/4
     */
    private SupervisorFile getSupervisorFile(SupervisorProjectFromsDTO poSupervisorProjectFromsDTO) {
        SupervisorFile file = new SupervisorFile();
        file.setProjectId(poSupervisorProjectFromsDTO.getSpfPrjid());
        file.setStageId(poSupervisorProjectFromsDTO.getSpfStaid());
        file.setSpmId(poSupervisorProjectFromsDTO.getSpfMilid());
        if (StringUtil.isNotBlank(poSupervisorProjectFromsDTO.getPcId())) {
            file.setPcId(poSupervisorProjectFromsDTO.getPcId());
        }
        return file;
    }

    /**
     * @param spf_prjid 项目ID
     * @param spf_milid 里程ID
     * @param fbid      分包ID
     * @param psType    文件类型
     * @Author:Zhangshuo
     * @Description:
     * @Date:12:25 2020/12/4
     */
    public String getFileOrderCode(String spf_prjid, String spf_staid, String spf_milid, String fbid, String psType) {
        SupervisorFile AoSupervisorFile = new SupervisorFile();
        AoSupervisorFile.setProjectId(spf_prjid);
        AoSupervisorFile.setStageId(spf_staid);
        AoSupervisorFile.setSpmId(spf_milid);
        AoSupervisorFile.setType(psType);
        if (StringUtil.isNotBlank(fbid)) {
            AoSupervisorFile.setPcId(fbid);
        }
        Integer count = 0;
        Map paraMap = new HashMap<>();
        paraMap.put("projectId", AoSupervisorFile.getProjectId());
        if ("055".equals(psType) || "061".equals(psType) || "081".equals(psType)) {
            // 特殊处理：初验： 055 验收报告 终验：061验收报告 验收阶段：081 验收报告 三种文档整体按顺序排列
            List<String> typeList = new ArrayList<String>();
            typeList.add("055");
            typeList.add("061");
            typeList.add("081");
            paraMap.put("typeList", typeList);
        } else if ("036".equals(psType) || "037".equals(psType)) {
            // 特殊处理：
            List<String> typeList = new ArrayList<String>();
            typeList.add("036");
            typeList.add("037");
            paraMap.put("type", AoSupervisorFile.getType());
        } else {
            if (StringUtils.isNotBlank(AoSupervisorFile.getPcId())) {
                paraMap.put("pcId", AoSupervisorFile.getPcId());
            }
            if (StringUtils.isNotBlank(AoSupervisorFile.getSpmId())) {
                paraMap.put("spmId", AoSupervisorFile.getSpmId());
            }
            paraMap.put("type", AoSupervisorFile.getType());
        }
        count = supervisorFileService.selectMaxOrderBySupervisorFile(paraMap) + 1;
        NumberFormat formatter = new DecimalFormat("000");
        String AsOrderNum = formatter.format(count);
        return AsOrderNum;
    }


    /**
     * @param request
     * @Author:zhaoyongke
     * @Description:項目管理----项目详情
     * @Date:13:22 2020/11/26
     * 编辑，查看，显示是哪个权限
     */
    @GetMapping(value = "projectDetail")
    @RequiresPermissions(value={"mgr:edit","mgr:view","mgr:show"},logical= Logical.OR)
    public String projectDetail(HttpServletRequest request) {
        String type = request.getParameter("type");
        String id = request.getParameter("id");
        String role = sysUserService.getUserRole(id);
        if ("zjlgcs".equals(role)) {
            //总监理完成后可以删除
            request.setAttribute("zjl", "1");
        }
        // 查询阶段表
        SupervisorProjectDTO supervisorProjectdto = getSupervisorProjectDTO(id);
        if ("m".equals(type)) {
            //编辑 项目结束后 收回承建单位权限
            Boolean iscj = projectUnitConstructionService.isCjUser(id);
            String status = supervisorProjectdto.getStatus();
            if ("003".equals(status)) {
                /*项目结束状态*/
                if (iscj) {
                    /*承建单位*/
                    request.setAttribute("message", "项目已经结束，您没有权限编辑！");
                    return "/error/lcerror";
                }
            }
        }
        //控制按钮
        bottonShow(request);
        /*判断是否是业主单位*/
        Boolean isyz = projectLeaderService.isYzUser(id);
        if (isyz) {
            request.setAttribute("isyz", "1");
        } else {
            request.setAttribute("isyz", "0");
        }
        // 查询业主单位
        ProjectLeaderDTO leaderdto = new ProjectLeaderDTO();
        leaderdto.setSupervisorProjectId(id);
        List<ProjectLeaderDTO> listyz = projectLeaderService.selectProjectLeaderList(leaderdto);
        // 城建单位表
        ProjectUnitConstructionDTO projectUnitConstruction = new ProjectUnitConstructionDTO();
        projectUnitConstruction.setSupervisorProjectId(id);
        List<ProjectUnitConstructionDTO> listcj = projectUnitConstructionService.selectProjectUnitList(projectUnitConstruction);
        // 查询分包表
        ProjectContractDTO projectContract = new ProjectContractDTO();
        projectContract.setProjectId(id);
        List<ProjectContract> listfb = projectContractService.selectPackge(projectContract);
        // 查询项目阶段
        SupervisorProjectStageDTO dto = new SupervisorProjectStageDTO();
        dto.setProjectId(id);
        List<SupervisorProjectStageDTO> listStage = supervisorProjectStageService.selectProjectStage(dto);
        Boolean isProjectYc = false;
        /*判断项目阶段和里程 是否延期*/
        for (int i = 0; i < listStage.size(); i++) {
            try {
           /*     SupervisorProjectStageDTO stageDTO = listStage.get(i);
                String stageId=stageDTO.getId();
                String stageNo = stageDTO.getStageNo();
                if(!"005".equals(stageNo)){
                    SupervisorProjectStage  stage= supervisorProjectStageService.selectByPrimaryKey(stageId);
                    *//*获取里程*//*
                    SupervisorProjectMilepost  milepost=new SupervisorProjectMilepost();
                    milepost.setSupervisorProjectStageId(stageId);
                    List<SupervisorProjectMilepost> listMilepost = supervisorProjectMilepostService.select(milepost);
                    Boolean  isyc=false;
                    *//*处理里程延迟状态*//*
                    for (int j = 0; j <listMilepost.size() ; j++) {
                        SupervisorProjectMilepost milepostl = listMilepost.get(j);
                        *//*002代表查看项目时候自动计算   001 点击完成按钮时候计算 状态*//*
                       String lcstatus=updategetLcStatus(stage,milepostl,"002");
                        if(StringUtil.isNotBlank(lcstatus)){
                            if("3".equals(lcstatus)){
                                *//*延迟*//*
                                milepostl.setFinishStatus("3");
                                supervisorProjectMilepostService.updateByPrimaryKey(milepostl);
                                *//*里程延迟*//*
                                isyc=true;
                                *//*项目延迟*//*
                                isProjectYc=true;
                            }
                        }
                    }
                    if(isyc){
                        *//*里程延迟  阶段就延期  该项目就延期*//*
                        stage.setFinishStatus("3");
                        stageDTO.setFinishStatus("3");
                        supervisorProjectStageService.updateByPrimaryKey(stage);
                    }

                }*/

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        /*    if(isProjectYc){
         *//*修改延迟状态*//*
           SupervisorProject project=new SupervisorProject();
           project=supervisorProjectService.selectByPrimaryKey(id);
           project.setStatus("005");
           supervisorProjectService.updateByPrimaryKey(project);
       }*/

        SupervisorProjectMilepostDTO su = new SupervisorProjectMilepostDTO();
        su.setProjectId(id);
        List<SupervisorProjectMilepostDTO> AlistMilePost = supervisorProjectMilepostService.selectProjectmilepost(su);
        // 查询付款方式
        SupervisorProjectPayDTO payDTO = new SupervisorProjectPayDTO();
        payDTO.setSppPrjid(id);
        List<SupervisorProjectPayDTO> listpay = supervisorProjectPayService.selectSupervisorProjectPay(payDTO);


        ProjectPlaceDTO pacedto = new ProjectPlaceDTO();
        pacedto.setSupProjectId(supervisorProjectdto.getId());
        pacedto.setType("001");
        List<ProjectPlaceDTO> listpalce = projectPlaceService.selectPlace(pacedto);
        request.setAttribute("listpalce", listpalce);
        request.setAttribute("project", supervisorProjectdto);
        request.setAttribute("listyz", listyz);// 业主单位
        request.setAttribute("listcj", listcj);// 城建单位
        request.setAttribute("listStage", listStage);// 项目阶段
        request.setAttribute("listmilepost", AlistMilePost);// 项目阶段
        request.setAttribute("listfb", listfb);// 项目分包if
        request.setAttribute("listpay", listpay);// 查询付款方式
        return "/supervisor/projectManager/projectDetail";
    }

    /**
     * 校验 支付金额、开票金额的总额需小于监理的合同额+补充协议金额
     * @param id
     * @param jlPayMoney 当前的支付金额
     * @param jlInvoiceMoney 当前的开票金额
     * @return
     */
    @GetMapping(value = "/verifyJINE")
    @ResponseBody
    public ReType verifyJINE(String id,String jlPayMoney, String jlInvoiceMoney){
        if (StringUtil.isNotBlank(jlPayMoney) && StringUtil.isNotBlank(jlInvoiceMoney)){
            // 根据id查询当前项目
            SupervisorProject supervisorProject = supervisorProjectService.selectByPrimaryKey(id);
            // 查询所有的支付金额和开票金额
            SupervisorProjectDTO project = new SupervisorProjectDTO();
            project.setId(id);
            List<SupervisorPayRecordDTO> tList = supervisorPayRecordService.selectHk(project);

            if (!StringUtil.isNotBlank(supervisorProject.getBcxyMoney())){
                supervisorProject.setBcxyMoney("0");
            }
            // 计算监理合同额 + 补充协议额的
            BigDecimal sum = new BigDecimal(supervisorProject.getHtMoney()).add(new BigDecimal(supervisorProject.getBcxyMoney()));

            // 支付金额、开票金额
            BigDecimal zfje = new BigDecimal(jlPayMoney);
            BigDecimal kpje = new BigDecimal(jlInvoiceMoney);
            if (tList != null && tList.size() > 0){
                for (SupervisorPayRecordDTO supervisorPayRecordDTO : tList) {
                    zfje = zfje.add(new BigDecimal(supervisorPayRecordDTO.getZfMoney()));
                    kpje = kpje.add(new BigDecimal(supervisorPayRecordDTO.getFpMoney()));
                }
            }
            if (sum.compareTo(zfje)==-1){
                return ReType.error("支付金额需要小于合同额与补充协议额的总和");
            }
            if (sum.compareTo(kpje)==-1){
                return ReType.error("发票金额需要小于合同额与补充协议额的总和");
            }
            return ReType.success(200,"校验成功！");
        }else {
            return ReType.error("参数错误！");
        }
    }

    /**
     * @param request
     * @Author:zhaoyongke
     * @Description:控制按钮
     * @Date:12:23 2021/2/20
     */
    public void bottonShow(HttpServletRequest request) {
        //监发两签
        Boolean jflq = sysUserService.isHasPermission("file:usecstamp");
        if (jflq) {
            request.setAttribute("jflq", "1");
        }
        //监发三签
        Boolean jfsq = sysUserService.isHasPermission("file:thrstamp");
        if (jfsq) {
            request.setAttribute("jfsq", "1");
        }
        //承发三签
        Boolean cfsq = sysUserService.isHasPermission("file:uthrstamp");
        if (cfsq) {
            request.setAttribute("cfsq", "1");
        }
        //审批
        Boolean jlsp = sysUserService.isHasPermission("file:approval");
        if (jlsp) {
            request.setAttribute("jlsp", "1");
        }
        //审核
        Boolean jlsh = sysUserService.isHasPermission("file:check");
        if (jlsh) {
            request.setAttribute("jlsh", "1");
        }
        // 查看
        Boolean fview = sysUserService.isHasPermission("file:view");
        if (fview) {
            request.setAttribute("fview", "1");
        }
        // 导出
        Boolean fexport = sysUserService.isHasPermission("file:export");
        if (fexport) {
            request.setAttribute("fexport", "1");
        }
        //盖章
        Boolean fupseal = sysUserService.isHasPermission("file:stamp");
        if (fupseal) {
            request.setAttribute("fupseal", "1");
        }
        //签字
        Boolean fsign = sysUserService.isHasPermission("file:sign");
        if (fsign) {
            request.setAttribute("fsign", "1");
        }
        // 检查旁站  上传图片  确认上传 批量删除 插入图片
        Boolean fupimg = sysUserService.isHasPermission("file:upimg");
        if (fupimg) {
            request.setAttribute("fupimg", "1");
        }
        Boolean filelistdel = sysUserService.isHasPermission("file:listdel");
        if (filelistdel) {
            request.setAttribute("flistdel", "1");
        }


    }

    /**
     * @param project
     * @param model
     * @param page
     * @param limit
     * @Author:Zhangshuo
     * @Description:项目管理----项目列表
     * @Date:9:47 2020-12-12
     */
    @ApiOperation(value = "/showProjectList", httpMethod = "GET", notes = "展示项目")
    @GetMapping(value = "showProjectList")
    @ResponseBody
    public ReType showProjectList(SupervisorProjectDTO project, Model model, String page, String limit) {
        // (1) 业主单位 （2） 承建单位  查询自己参与的项目
        //（3） 项目经理  查询自己创建的和自己参与的
        //（4） 监理工程师 （5）技术负责人 查询自己参与的项目
        //（6） 市场人员  发布的
        // (7) 管理员 公司高层 工程部经理 质控 查看全部
        // （8）202224 分公司总经理  智能看到自己公司的项目


        //查询不是删除状态的项目
        project.setDestatus("000");
        project.setUserId(CommonUtil.getUserId());
        project.setField(humpToUnderline(project.getField()));
        //判断是否是管理员  公司高层  工程部经理  质控  :
        Subject subject = SecurityUtils.getSubject();
        if (subject.hasRole("admin") || subject.hasRole("gsgc") || subject.hasRole("zkjsry")) {
            project.setUserId(null);
        }

        // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
        // 分公司总经理  看到自己公司的
        // 分公司工程部经理  只能看到自己的
        if(subject.hasRole("fgszjl")  ||  subject.hasRole("gcbjl")  ||  subject.hasRole("fgsgcbjl")){
            // 分公司总经理  看到自己公司的
            SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
            // 公司Id
            String companyName = sysUser.getCompanyName();
            if(StringUtils.isBlank(companyName)){
                // 如果所所属公司为空  就不能显示出来信息
            }else{
                project.setUserId(null);
                project.setProjectOwner(companyName);
            }
        }

        ReType result = supervisorProjectService.show(project, Integer.valueOf(page), Integer.valueOf(limit));
        return result;
    }

    //排序字段处理
    public static String humpToUnderline(String name) {
        StringBuilder result = new StringBuilder();
        if (name != null && name.length() > 0) {
            // 将第一个字符处理成大写
            result.append(name.substring(0, 1).toUpperCase());
            // 循环处理其余字符
            for (int i = 1; i < name.length(); i++) {
                String s = name.substring(i, i + 1);
                // 在大写字母前添加下划线
                if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
                    result.append("_");
                }
                // 其他字符直接转成大写
                result.append(s.toUpperCase());
            }
        }
        return result.toString();
    }

    /*
     * 项目管理----回收站列表查询
     * */

    @ApiOperation(value = "/showProjectListHs", httpMethod = "GET", notes = "展示项目")
    @GetMapping(value = "showProjectListHs")
    @ResponseBody
    public ReType showProjectListHs(SupervisorProjectDTO project, HttpServletResponse response, Model model, String page, String limit) {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        // 查询已删除状态的项目 010
        project.setStatus("000");
        project.setUserId(CommonUtil.getUserId());
        //判断是否是管理员  公司高层  工程部经理  质控  :
        Subject subject = SecurityUtils.getSubject();
        if (subject.hasRole("admin")) {
            project.setUserId(null);
        }
        ReType re = supervisorProjectService.show(project, Integer.valueOf(page), Integer.valueOf(limit));
        return re;
    }

    /**
     * @param project
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 查询项目账号信息
     * @Date:22:26 2020/12/14
     */
    @GetMapping(value = "showProjectListAc")
    @ResponseBody
    public ReType showProjectListAc(SupervisorProjectDTO project, Model model, String page, String limit) {
        ReType re = new ReType();
        List<JSONObject> relist = new ArrayList<JSONObject>();
        String projectId = project.getProjectId();
        //查询业主管理员账号:
        List<SysUserDTO> sysUserDTOS = sysUserService.selectProjectAdmin(projectId);
        if (sysUserDTOS != null) {
            if(sysUserDTOS.size()>0){
                SysUserDTO admin = sysUserDTOS.get(0);
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("realName", admin.getRealName());
                jsonObject.put("username", admin.getUsername());
                jsonObject.put("createBy", admin.getCreateBy());
                jsonObject.put("createDate", DateUtil.formatDate(admin.getCreateDate(), "yyyy-MM-dd HH:mm:ss"));
                jsonObject.put("companyName", admin.getCompanyName());
                jsonObject.put("userId", admin.getId());
                jsonObject.put("userType", "业主单位管理员");
                relist.add(jsonObject);
                re.setData(relist);
            }

        } else {
            log.warn("没有查询到项目管理员账号");
        }
        // 查询业主单位
        ProjectLeaderDTO projectLeaderdto = new ProjectLeaderDTO();
        projectLeaderdto.setSupervisorProjectId(projectId);
        List<ProjectLeaderDTO> listleader = projectLeaderService.selectProjectLeaderList(projectLeaderdto);
        for (int i = 0; i < listleader.size(); i++) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("realName", listleader.get(i).getRealName());
            jsonObject.put("username", listleader.get(i).getUsername());
            jsonObject.put("createBy", listleader.get(i).getCreateBy());
            jsonObject.put("createDate", listleader.get(i).getCreateDate());
            jsonObject.put("companyName", listleader.get(i).getCompanyName());
            jsonObject.put("userId", listleader.get(i).getProjectLeader());
            jsonObject.put("userType", "业主单位");
            relist.add(jsonObject);
        }
        //查询承建单位
        ProjectUnitConstructionDTO unitConstructiondto = new ProjectUnitConstructionDTO();
        unitConstructiondto.setSupervisorProjectId(projectId);
        List<ProjectUnitConstructionDTO> listcj = projectUnitConstructionService.selectProjectUnitList(unitConstructiondto);
        for (int i = 0; i < listcj.size(); i++) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("realName", listcj.get(i).getRealName());
            jsonObject.put("username", listcj.get(i).getUsername());
            jsonObject.put("createBy", listcj.get(i).getCreateBy());
            jsonObject.put("createDate", listcj.get(i).getCreateDate());
            jsonObject.put("companyName", listcj.get(i).getCompanyName());
            jsonObject.put("userId", listcj.get(i).getProjectManager());
            jsonObject.put("userType", "承建单位");
            relist.add(jsonObject);
        }
        return re;
    }

    /**
     * 项目管理----恢复回收站
     **/
    @ApiOperation(value = "/doHs", httpMethod = "POST", notes = "恢复回收站")
    @Log(desc = "恢复回收站", type = Log.LOG_TYPE.DEL)
    @PostMapping(value = "doHs")
    @ResponseBody
    public JsonUtil doHs(@RequestParam String ids) {
        JsonUtil re = new JsonUtil();
        if (StringUtils.isEmpty(ids)) {
            return JsonUtil.error("获取数据失败");
        }
        try {
            List<String> list = Tutil.split(ids);
            for (int i = 0; i < list.size(); i++) {
                String id = list.get(i);
                SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
                /*恢复原来状态*/
                if (StringUtil.isNotBlank(project.getOldStatus())) {
                    project.setStatus(project.getOldStatus());
                } else {
                    project.setStatus("001");
                }
                supervisorProjectService.updateByPrimaryKey(project);
                re.setFlag(true);
                re.setMsg("操作成功");
            }
        } catch (Exception e) {
            re.setFlag(false);
            re.setMsg("操作失败：" + e.getMessage());
            e.printStackTrace();
        }
        return re;

    }


    /**
     * 项目管理----放到回收站
     **/
    @ApiOperation(value = "/deleteHs", httpMethod = "POST", notes = "放入回收站项目")
    @Log(desc = "放入回收站", type = Log.LOG_TYPE.DEL)
    @PostMapping(value = "deleteHs")
    @ResponseBody
    public JsonUtil deleteHs(@RequestParam String ids) {
        if (StringUtils.isEmpty(ids)) {
            return JsonUtil.error("获取数据失败");
        }
        JsonUtil re = new JsonUtil();
        try {
            List<String> list = Tutil.split(ids);
            for (int i = 0; i < list.size(); i++) {
                String id = list.get(i);
                SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
                /*删除前保存原来的状态，还原后恢复原来状态*/
                project.setOldStatus(project.getStatus());
                project.setStatus("000");
                supervisorProjectService.updateByPrimaryKey(project);
                re.setFlag(true);
                re.setMsg("操作成功");
            }
        } catch (Exception e) {
            re.setMsg("擦作失败：" + e.getMessage());
            re.setFlag(false);
            e.printStackTrace();
        }
        return re;
    }

    @ApiOperation(value = "/resetPassword", httpMethod = "POST", notes = "重置密码")
    @Log(desc = "重置密码", type = Log.LOG_TYPE.DEL)
    @PostMapping(value = "resetPassword")
    @ResponseBody
    public JsonUtil resetPassword(SysUser sysUser) {
        JsonUtil re = new JsonUtil();
        try {
            String id = sysUser.getId();
            if (StringUtils.isEmpty(id)) {
                return JsonUtil.error("获取用户Id失败");
            }
            SysUser sysUserselect = sysUserService.selectByPrimaryKey(id);
            sysUserselect.setPassword("12345678");
            sysUserselect.setUpdateBy(CommonUtil.getUserId());
            sysUserselect.setUpdateDate(DateUtil.getCurrentDateTime());
            String pwd = Md5Util.getMD5(sysUserselect.getPassword().trim(), sysUserselect.getUsername().trim());
            sysUserselect.setPassword(pwd);
            sysUserService.updateByPrimaryKey(sysUserselect);
        } catch (Exception e) {
            re.setMsg(e.getMessage());
            re.setFlag(false);
            e.printStackTrace();
        }
        re.setFlag(true);
        re.setMsg("操作成功");
        return re;
    }


    /**
     * @param ids
     * @Author:Zhangshuo
     * @Description:删除回收站项目数据
     * @Date:20:23 2020-12-11
     */
    @ApiOperation(value = "/delprjfromrecycle", httpMethod = "POST", notes = "从回收站中删除项目")
    @Log(desc = "从回收站中删除项目", type = Log.LOG_TYPE.DEL)
    @PostMapping(value = "delprjfromrecycle")
    @ResponseBody
    public JsonUtil deleteProjects(@RequestParam String[] ids) {
        try {
            doDelete(ids);
            return JsonUtil.sucess("删除成功。");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonUtil.error("删除失败，" + e.getMessage());
        }
    }

    /**
     * @param
     * @Author:Zhangshuo
     * @Description:清除当前登录回收站
     * @Date:21:47 2020-12-11
     */
    @ApiOperation(value = "/delallprjfromrecycle", httpMethod = "POST", notes = "清除回收站中项目")
    @Log(desc = "清除回收站中项目", type = Log.LOG_TYPE.DEL)
    @PostMapping(value = "delallprjfromrecycle")
    @ResponseBody
    public JsonUtil deleteAllProjects() {
        JsonUtil jsonUtil = new JsonUtil();
        try {
            String AsUserId = CommonUtil.getUserId();
            if (StringUtil.isNotBlank(AsUserId)) {
                SupervisorProject supervisorproject = new SupervisorProject();
                supervisorproject.setCreateBy(AsUserId);
                supervisorproject.setStatus("000");
                List<SupervisorProject> AlstProjects = supervisorProjectService.select(supervisorproject);
                int AiCnt = AlstProjects.size();
                if (AiCnt == 0) {
                    return JsonUtil.error("没有需要删除的信息。");
                }
                String[] AyDelPrjIds = new String[AiCnt];
                for (int i = 0; i < AiCnt; i++) {
                    AyDelPrjIds[i] = AlstProjects.get(i).getId();
                }
                doDelete(AyDelPrjIds);
                jsonUtil.setFlag(true);
                jsonUtil.setMsg("删除成功");
                jsonUtil.setData(AyDelPrjIds);
                return jsonUtil;
            } else {
                return JsonUtil.error("用户验证失败。");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JsonUtil.error("删除失败，" + e.getMessage());
        }
    }

    /**
     * @param ids
     * @Author:Zhangshuo
     * @Description:执行删除函数
     * @Date:21:38 2020-12-11
     */
    private void doDelete(String[] ids) {
        int AiFlag = supervisorProjectService.deleteProjectsFromRecycle(ids);
        if (AiFlag > 0) {
            // 修改流程无无效
//            supervisorFileService.deleteAffairCaseByProjectIds(ids);
            //文件表
            supervisorFileService.deleteByProjectIds(ids);
            //表单表
            supervisorProjectFormsService.deleteByProjectIds(ids);
            // 分包数据
            projectContractService.deleteByProjectIds(ids);
            // 项目负责人
            projectLeaderService.deleteByProjectIds(ids);
            // 承建单位
            projectUnitConstructionService.deleteByProjectIds(ids);
            // 阶段数据
            supervisorProjectStageService.deleteByProjectIds(ids);
            // 里程数据
            supervisorProjectMilepostService.deleteByProjectIds(ids);
            // 付款方式
            supervisorProjectPayService.deleteByProjectIds(ids);
            // 删除标签--用户
            deleteUserTag(ids);


        }
    }

    /**
     * @param ids
     * @Author:zhaoyongke
     * @Description:项目删除后清除 tags
     * @Date:14:32 2021/3/16
     */
    public void deleteUserTag(String[] ids) {
        CurrentUser currentUser = CommonUtil.getUser();
        for (int y = 0; y < ids.length; y++) {
            String proId = ids[y];
            Example ecj = new Example(SysUser.class);
            Example.Criteria ccj = ecj.createCriteria();
            ccj.andIsNotNull("tags");
            ccj.andLike("tags", "%" + proId + "%");
            List<SysUser> listuser = sysUserService.selectByExample(ecj);
            if (listuser.size() > 0) {
                for (int i = 0; i < listuser.size(); i++) {
                    SysUser user = listuser.get(i);
                    String AsTags = user.getTags();
                    if (StringUtil.isNotBlank(AsTags)) {
                        String[] ayTags = AsTags.split(";");
                        String strtag = "";
                        for (int t = 0; t < ayTags.length; t++) {
                            String tagstr = ayTags[t];
                            if (tagstr.indexOf(proId) > -1) {
                                strtag = tagstr + ";";
                                break;
                            }
                        }
                        if (StringUtil.isNotBlank(strtag)) {
                            String newstr = AsTags.replace(strtag, "");
                            user.setTags(newstr);
                            sysUserService.updateByPrimaryKey(user);
                            if (currentUser.getId().equals(user.getId())) {
                                currentUser.setTags(newstr);
                                Session session = com.qili.core.shiro.Principal.getSession();
                                session.setAttribute("currentPrincipal", currentUser);
                            }

                        }
                    }


                }

            }

        }

    }

    /**
     * 项目管理----删除项目
     **/
    @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除项目")
    @Log(desc = "删除项目", type = Log.LOG_TYPE.DEL)
    @PostMapping(value = "del")
    @ResponseBody
    public JsonUtil del(String id) {
        if (StringUtils.isEmpty(id)) {
            return JsonUtil.error("获取数据失败");
        }
        JsonUtil json = supervisorProjectService.del(id);
        return json;
    }

    /**
     * @param supervisorProject
     * @return
     */
    @ApiOperation(value = "/addProject", httpMethod = "POST", notes = "创建项目")
    @PostMapping(value = "addProject")
    @ResponseBody
    public JsonUtil addProject(SupervisorProject supervisorProject) {
        JsonUtil jsonUtil = new JsonUtil();
        TransactionStatus transactionStatus = manager.getTransaction(new DefaultTransactionDefinition());
        try {
            supervisorProjectService.insert(supervisorProject);
            //提交事务
            manager.commit(transactionStatus);
            jsonUtil.setFlag(true);
            jsonUtil.setMsg("创建成功");
        } catch (Exception e) {
            jsonUtil.setFlag(false);
            jsonUtil.setMsg("创建失败" + e.getMessage());
            manager.rollback(transactionStatus);
        }
        return null;
    }

    /*
     *  文件上传
     * */
/*    @RequestMapping(value = "/addFile", method = RequestMethod.POST)
    @ResponseBody*/

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public JsonUtil addFile(MultipartFile filedata, SupervisorProjectDTO dto, HttpServletRequest request)  throws Exception {

//        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
//        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRED);
        //返回数据
        JsonUtil re = new JsonUtil();
        String type = request.getParameter("type");//文件类型
        String projectid = dto.getId();// 项目id
        String lockkey = "jlwj_" + projectid + "_" + type;
        String uuId = IdUtil.simpleUUID();
     try {
//            lock(lockkey, uuId);
            String uploadtype = dto.getUploadType();
            String userid = CommonUtil.getUserId(); // 当前用户信息
            String spmid = dto.getSpmId();// 里程id
            String stageId = dto.getStageId();//阶段id
            String fs_status = request.getParameter("fs_status");// 上传的时候 对应的状态p'r
            String fbId = request.getParameter("fbId");//分包表id
            JSONObject jsonObject = new JSONObject();
            String filename = filedata.getOriginalFilename();

            if (StringUtil.isNotBlank(fbId)) {
                Boolean ischeck = checkFbCj(fbId, projectid);
                if (!ischeck) {
                    re.setMsg("该分包没有承建单位，不能上传文件");
                    re.setFlag(false);
                    return re;
                }
            }
            String role = sysUserService.getUserRole(projectid);
            if ("xmjl".equals(role) || "cj".equals(role) || "zjlgcs".equals(role) || "jlgcs".equals(role)) {
                if ("cj".equals(role)) {
                    BaseDict wjdict = DictUtil.getDictByCode(DictTypes.WJ, type);
                    String level11 = wjdict.getBadtLevel11();
                    if (level11.indexOf("cj") < 0) {
                        re.setMsg("您没有权限上传文档");
                        re.setFlag(false);
                        return re;
                    }
                }

            } else {
                re.setMsg("您没有权限上传文档");
                re.setFlag(false);
                return re;
            }

            /*项目大事记*/
            projectBigEventService.saveProejctBigEvent(projectid, spmid, stageId);
            //对文件中图片和文件的名称做处理
            JsonUtil error = doSomeSpecialThings(dto, uploadtype);
            if (error != null) {
                re.setFlag(false);
                re.setMsg(error.getMsg());
                return error;
            }
            if ((StringUtil.isBlank(uploadtype)) || (!uploadtype.equals("002"))) {
                //更新阶段和里程状态
                updateStageAndMilePostStatus(spmid, stageId, fs_status, jsonObject, type, fbId);
            }
            //上传文件以及保存数据
            savedoUploadAndSaveFile(filedata, dto, uploadtype, userid, spmid, stageId, projectid, fbId, jsonObject, filename);

            if (jsonObject.get("wj_status") == null) {
                jsonObject.put("wj_status", "");
            }
            if (jsonObject.get("lc_status") == null) {
                jsonObject.put("lc_status", "");
            }
            if (jsonObject.get("jd_status") == null) {
                jsonObject.put("jd_status", "");
            }
            re.setData(jsonObject);
            re.setFlag(true);
            return re;
        } catch (Exception e) {
            e.printStackTrace();
            re.setFlag(false);
            re.setMsg("文件上传异常，" + e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return re;

//     finally {
//            unlock(lockkey, uuId);
//            return re;
//        }
    }

    /**
     * @param fbId
     * @Author:zhaoyongke
     * @Description: 检查分包有没有承建单位 没有承建单位不能上传文件
     * @Date:16:18 2021/1/21
     */
    public Boolean checkFbCj(String fbId, String projectId) {
        Boolean isCheck = true;
        ProjectContract contract = projectContractService.selectByPrimaryKey(fbId);
        String code = contract.getCode();
        if (StringUtil.isNotBlank(code)) {
            //查询承建单位
            ProjectUnitConstruction unitConstruction = new ProjectUnitConstruction();
            unitConstruction.setSupervisorProjectId(projectId);
            unitConstruction.setConstructionSubContractNumber(code);
            int count = projectUnitConstructionService.selectCount(unitConstruction);
            if (count == 0) {
                isCheck = false;
            }
        }
        return isCheck;
    }
    @RequestMapping(value = "/addFile", method = RequestMethod.POST)
    @ResponseBody
    public JsonUtil File(@RequestParam(value = "file", required = false) MultipartFile filedata, SupervisorProjectDTO dto, HttpServletRequest request) {
        JsonUtil re =new JsonUtil();
        String projectid = dto.getId();// 项目id
        String type = request.getParameter("type");//文件类型
        String lockkey = "jlwj_" +projectid+"_"+ type;
        String uuId = IdUtil.simpleUUID();
        try {
            lock(lockkey,uuId);
        // redis 锁 防止 编号重复
            JsonUtil  jsonUtil= ((SupervisorController) AopContext.currentProxy()).addFile(filedata, dto, request);
            re.setFlag(jsonUtil.isFlag());
            re.setData(jsonUtil.getData());
            re.setMsg(jsonUtil.getMsg());
            re.setJosnObj(jsonUtil.getJosnObj());
            re.setStatus(jsonUtil.getStatus());
        }catch (Exception ex){
           re.setFlag(false);
           re.setMsg("文件上传异常，" + ex.getMessage());
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            System.out.println(ex.getMessage());
        }finally {
            unlock(lockkey,uuId);
            return re;
        }
    }

    public void unlock(String key, String uuId) {
        if (uuId.equals(stringRedisTemplate.opsForValue().get(key))) {
            stringRedisTemplate.delete(key);
        }
    }

    public void lock(String key, String uuId) {
        int k = 0;
        for (; ; ) {

            System.out.println(redisService);
            boolean r = stringRedisTemplate.opsForValue().setIfAbsent(key, uuId);
            stringRedisTemplate.expire(key, 600, TimeUnit.SECONDS);

            if (r) {
                return;
            }
            if (k++ >= 1500) {
                throw new RuntimeException("lock error key = " + key);
            }
            int i = new Random().nextInt(30);
            try {
                TimeUnit.MILLISECONDS.sleep(300 + i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * @param filedata
     * @param dto
     * @param uploadtype
     * @param userid
     * @param spmid
     * @param stageId
     * @param projectid
     * @param fbId
     * @param jsonObject
     * @param filename
     * @Description: 上传文件已经保存到数据库中
     * @Author:Zhangshuo
     * @Date:21:51 2020-12-20
     */
    @Transactional
    public void savedoUploadAndSaveFile(MultipartFile filedata, SupervisorProjectDTO dto, String uploadtype, String userid, String spmid, String stageId, String projectid, String fbId, JSONObject jsonObject, String filename) throws Exception {
        //上传文件
        String AsFileStuffix = FilePathUtil.getFileSufiix(filename);
        /*检验文件格式*/
        updatejyFileType(AsFileStuffix, dto.getType());
        /*校验文件名称*/
        updatejyFileName(filename, dto.getType());

        UploadType uploadType = getFileUploadType(dto, spmid, projectid, fbId, AsFileStuffix, uploadtype);
        // 承建合同文件  取消自动命名 2021 12 06 zhaoyongke
        if("006".equals(dto.getType())){
            // 这些文件 不需要系统生成文件名称
            uploadType.setFileName(filename);
        }
        LoadType loadType = uploadUtil.upload(filedata, uploadType);
        if("006".equals(dto.getType())){
            //判断上传的文件是否重复
            SupervisorFile  supervisorFile=new SupervisorFile();
            File currentFile = loadType.getCurrentFile();
            String path = currentFile.getPath();
            supervisorFile.setUrl(path);
            int i = supervisorFileService.selectCount(supervisorFile);
            if(i>0){
                throw   new Exception("存在同名文件，请修改文件名后再上传！");
            }
        }
        //文件名称
        String AsNewFileName = uploadType.getFileName();
        //保存文件表
        SupervisorFile filedto = saveSupervisorFile(dto, userid, spmid, stageId, projectid, fbId, loadType, AsNewFileName, uploadType.getInd());

        //  20220627  增加第一次上传文件的时间  和 更新最后一次上传时间
        SupervisorProject  project=supervisorProjectService.selectByPrimaryKey(projectid);
        if(StringUtils.isBlank(project.getUploadBeginTime())){
            project.setUploadBeginTime(DateUtil.getCurrentDateString());
        }
        project.setUploadLastTime(DateUtil.getCurrentDateString());
        supervisorProjectService.updateByPrimaryKey(project);

        //解析文件数据
        jsonObject.put("id", filedto.getId());
        jsonObject.put("filename", AsNewFileName);
        HashMap map =new HashMap();
        try {
            map = saveparsingFileData(loadType.getFilePath(), dto, fbId);
        } catch (Exception e) {
            throw  new  Exception("请按照模板文件格式上传,目前只支持2007版以上的Word文件（后缀名为.docx）");
        }
        /*reson 变更处理表更原因*/
        jsonObject.put("bgreason", map.get("reason"));

    }

    /**
     * @param AsFileStuffix
     * @param type
     * @Author:zhaoyongke
     * @Description:校验文件类型 是否和字典中的值一致
     * @Date:16:51 2021/1/12
     */
    public void updatejyFileType(String AsFileStuffix, String type) throws Exception {
        BaseDict wjdict = DictUtil.getDictByCode(DictTypes.WJ, type);
        Boolean isTrue = false;
        /*文件类型是否正确判断*/
        String dicwjtype = wjdict.getBadtLevel6();
        if (StringUtil.isNotBlank(dicwjtype)) {
            String[] dictypesz = dicwjtype.split(",");
            if (dictypesz.length > 0) {
                for (int i = 0; i < dictypesz.length; i++) {
                    String wjtype = dictypesz[i].toLowerCase();
                    String stuffix = AsFileStuffix.toLowerCase() + "";
                    if (stuffix.indexOf(wjtype) != -1) {
                        isTrue = true;
                        break;
                    }
                }
            } else {
                isTrue = true;
            }
        } else {
            isTrue = true;
        }
        if (!isTrue) {
            throw new Exception("正确的文件格式为：" + dicwjtype);
        }
    }

    /**
     * @param fileName
     * @param type
     * @Author:zhaoyongke
     * @Description: 校验文件名称
     * @Date:17:20 2021/1/12
     */
    public void updatejyFileName(String fileName, String type) throws Exception {
        BaseDict wjdict = DictUtil.getDictByCode(DictTypes.WJ, type);
        String isjy = wjdict.getBadtLevel7();
        String dictFileName = wjdict.getBadtName();
        if ("1".equals(isjy)) {
            if (fileName.indexOf(dictFileName) == -1) {
                throw new Exception("您上传的文件名称中必须包含：" + dictFileName);
            }
        }
    }

    /**
     * @param dto
     * @param uploadtype
     * @Description:
     * @Author:Zhangshuo
     * @Date:21:48 2020-12-20
     */
    private JsonUtil doSomeSpecialThings(SupervisorProjectDTO dto, String uploadtype) {
        String AsType = dto.getType();
        //002 上传图片方式
        if ("002".equals(uploadtype) && !"093".equals(AsType) && !"040".equals(AsType)) {

            if ("108".equals(AsType) || "109".equals(AsType) || "087".equals(AsType) || "088".equals(AsType)) {
                //承建付款申请 和 监理付款申请 不包含部位
                String positonName = dto.getPositionName();
                dto.setPositionName("第" + positonName + "次");
            } else {
                if (StringUtil.isBlank(dto.getPositionName())) {
                    return JsonUtil.error("部位不允许为空！！");
                } else {
                    // 部位为汉字
                    String reg = "[\\u4e00-\\u9fa5]+";
                    boolean result = dto.getPositionName().matches(reg);
                    if (!result) {
                        return JsonUtil.error("部位请填写汉字！！");
                    }
                }
            }
        }
        return null;
    }

    /**
     * @param spmid
     * @param stageId
     * @param fs_status
     * @param jsonObject
     * @Description:更新阶段和里程状态
     * @Author:Zhangshuo
     * @Date:22:31 2020-12-18
     */
    private void updateStageAndMilePostStatus(String spmid, String stageId, String fs_status, JSONObject jsonObject, String type, String fbId) {
        // 里程
        SupervisorProjectMilepost supervisorProjectMilepost = supervisorProjectMilepostService.selectByPrimaryKey(spmid);
        // 阶段
        SupervisorProjectStage stage = supervisorProjectStageService.selectByPrimaryKey(stageId);
        String stepNum = supervisorProjectMilepost.getStepNum();
        // 里程本身的状态
        String finishStatus = supervisorProjectMilepost.getFinishStatus();
        if ("038".equals(type) || "039".equals(type) || "042".equals(type) || "043".equals(type) || "044".equals(type) || "045".equals(type)) {
            //到货验收 里面的文件类型 单独处理 文件状态记录到分包表中了
            ProjectContract contract = projectContractService.selectByPrimaryKey(fbId);
            String stepNumFb = contract.getStepNum();
            String finishStatusFb = contract.getFinishStatus();// 里程本身的状态
            String[] ayStatus = stepNumFb.split(",");
            String asPostStartIdx = fs_status.substring(0, 1);// 例如  10  20  截取  为  1 , 2
            String strsatus = ayStatus[Integer.valueOf(asPostStartIdx) - 1];
            if (strsatus.substring(1, 2).equals("0") && ("0".equals(finishStatusFb) || "1".equals(finishStatusFb))) {// 判断当前文件类型的状态
                ayStatus[Integer.valueOf(asPostStartIdx) - 1] = fs_status;// 更新文件类型状态
                String str = Arrays.toString(ayStatus).replace("[", "").replace("]", "").replace(" ", "");
                contract.setStepNum(str);
                // 更新状态字符串
                if ("0".equals(finishStatusFb)) {
                    contract.setFinishStatus("1");//进行中
                }
                projectContractService.updateByPrimaryKey(contract);
                jsonObject.put("wj_status", "1");
            }
        } else {
            String[] ayStatus = stepNum.split(",");
            String asPostStartIdx = fs_status.substring(0, 1);// 例如  10  20  截取  为  1 , 2
            String strsatus = ayStatus[Integer.valueOf(asPostStartIdx) - 1];
            // 该里程的状态为 进行中  或未开始 或 本文件类型为未开始的状态
            if (strsatus.substring(1, 2).equals("0") && ("0".equals(finishStatus) || "1".equals(finishStatus) || "3".equals(finishStatus))) {// 判断当前文件类型的状态
                ayStatus[Integer.valueOf(asPostStartIdx) - 1] = fs_status;// 更新文件类型状态
                String str = Arrays.toString(ayStatus).replace("[", "").replace("]", "").replace(" ", "");
                supervisorProjectMilepost.setStepNum(str);
                // 更新状态字符串
                supervisorProjectMilepostService.updateByPrimaryKey(supervisorProjectMilepost);
                jsonObject.put("wj_status", "1");
            }
        }
        if ("0".equals(finishStatus)) {
            supervisorProjectMilepost.setFinishStatus("1");//进行中
            supervisorProjectMilepostService.updateByPrimaryKey(supervisorProjectMilepost);
            jsonObject.put("lc_status", "1");// 里程进行中
        }
        if ("0".equals(stage.getFinishStatus())) {
            stage.setFinishStatus("1");//进行中
            supervisorProjectStageService.updateByPrimaryKey(stage);
            jsonObject.put("jd_status", "1");// 阶段
        }
    }

    /**
     * @param dto
     * @param userid
     * @param spmid
     * @param stageId
     * @param projectid
     * @param fbId
     * @param loadType
     * @param asNewFileName
     * @Author:Zhangshuo
     * @Description:保存数据到文件表
     * @Date:22:21 2020-12-08
     */
    public SupervisorFile saveSupervisorFile(SupervisorProjectDTO dto, String userid, String spmid, String stageId, String projectid, String fbId, LoadType loadType, String asNewFileName, Integer ind)  throws  Exception {
        SupervisorFile filedto = new SupervisorFile();
        filedto.setFileName(asNewFileName);
        filedto.setFileType(loadType.getSuffix());
        filedto.setType(dto.getType());
        filedto.setCreateBy(userid);
        filedto.setCreateDate(new Date());
        filedto.setUrl(loadType.getFilePath());
        filedto.setInd(ind);
        if (null != fbId && !"".equals(fbId)) {
            filedto.setPcId(fbId);// 分包id
        }
        filedto.setParentId(dto.getParentId());
        filedto.setPositionName(dto.getPositionName());
        filedto.setProjectId(projectid);// 项目id
        filedto.setSpmId(spmid);// 里程id
        filedto.setStageId(stageId);// 阶段id
        supervisorFileService.insert(filedto);
        supervisorFileService.setFilePathDics(filedto);
        // 解析文件  保存文本用于 智能检索
        try {
            supervisorFileService.parseFileToText(filedto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return filedto;
    }

    /**
     * @param psFileName
     * @param pSupervisorPrjDTO
     * @param pFbId
     * @Description:解析文件数据
     * @Author:Zhangshuo
     * @Date:22:26 2020-12-15
     */
    public HashMap saveparsingFileData(String psFileName, SupervisorProjectDTO pSupervisorPrjDTO, String pFbId) throws Exception {
        HashMap map = new HashMap();
        switch (pSupervisorPrjDTO.getType()) {
            case "064":
                if (!psFileName.toLowerCase().endsWith("docx")) {
                    throw new RuntimeException("请按照模板文件格式上传，目前只支持2007版以上的Word文件（后缀名为.docx）");
                }
                //处理货物清单
                savedoEquipmentList(psFileName, pSupervisorPrjDTO, pFbId);
                break;
            case "093":
                String parentId = pSupervisorPrjDTO.getParentId();
                /*过滤掉附件*/
                if (StringUtil.isBlank(parentId)) {
                    if (!psFileName.toLowerCase().endsWith("docx")) {
                        throw new RuntimeException("请按照模板文件格式上传，目前只支持2007版以上的Word文件（后缀名为.docx）");
                    }
                    //工程变更单
                    map = saveGcBgd(psFileName, pSupervisorPrjDTO, pFbId);
                }

                break;
            default:
        }
        return map;
    }

    /**
     * @param pFilePath
     * @param pDto
     * @param pDto
     * @Description:处理货物清单
     * @Author:Zhangshuo
     * @Date:9:42 2020-12-09
     */
    private void savedoEquipmentList(String pFilePath, SupervisorProjectDTO pDto, String pFbId) throws Exception {
        int AiTableIndex = 1;
        String AsFormId = IdUtil.simpleUUID();
        parsingFileDataToForm(pFilePath, pDto, AsFormId);
        // 检验 货物清单格式
        List<List<String>> checkGs = WordUtil.getWordTableData(pFilePath, AiTableIndex, 1);
        int size = checkGs.size();
        int i = 0;
        for (List<String> rowdata : checkGs) {
            if (i == 0) {
                //序号
                String xh = rowdata.get(0) + "";
                //区域
                String qy = rowdata.get(1) + "";
                if (!"序号".equals(xh) || !"区域".equals(qy)) {
                    throw new RuntimeException("请按照模板格式导入");
                }
                break;
            }

            i++;
        }

        // 获取 货物清单表格中的数据
        List<List<String>> AlstTableData = WordUtil.getWordTableData(pFilePath, AiTableIndex, 2);
        if(AlstTableData!=null){
            if(AlstTableData.size()>0){
                for (int j = 0; j <AlstTableData.size() ; j++) {
                    String str = AlstTableData.get(j)+"";
                    if(StringUtil.isNotBlank(str)){
                        if(str.indexOf("填表说明")>0){
                            AlstTableData.remove(j);
                        }
                    }
                }
            }

        }

        int AiRowCnt = AlstTableData.size();
        // 将解析的表格数据保存到fromdata 表中
        for (List<String> rowdata : AlstTableData) {
            parsingFileDataToFormData(AiTableIndex, AsFormId, AiRowCnt, rowdata);
        }
        //获取合同比对报告路径
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setProjectId(pDto.getId());
        supervisorFile.setType("044");
        supervisorFile.setPcId(pFbId);
        SupervisorFile AoFile = supervisorFileService.selectOne(supervisorFile);
        if (!isNull(AoFile)) {
            String AsTargetFileName = AoFile.getUrl();
            if (StringUtil.isNotBlank(AsTargetFileName)) {
                HashMap mapprojectinfo = doProjectInfo(pDto.getId(), pFbId);
                // 将获取的数据 插入 合同对比报告中
                WordUtil.savecompareContractFillList(mapprojectinfo, AlstTableData, AsTargetFileName);
            }
        }
    }

    /**
     * @param pFilePath
     * @param pDto
     * @param pFbId
     * @Author:zhaoyongke
     * @Description: 处理工程变更单
     * @Date:13:38 2021/1/14saveGcBgd
     */
    public HashMap saveGcBgd(String pFilePath, SupervisorProjectDTO pDto, String pFbId) throws Exception {
        int AiTableIndex = 1;
        String AsFormId = IdUtil.simpleUUID();
        /*        String url="D:\\template\\doc\\工程变更单模板11.docx";*/
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            int y = i + 1;
            list.add("PO_F" + y);
        }
        //获取变更文档中的数据

        HashMap maptext = null;
        try {
            maptext = WordUtil.getTextByLebel(pFilePath, list);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            throw new Exception(e.getMessage());
        }
        /*解析的数据保存到form表中*/
        saveBgdDataToForm(pFilePath, pDto, AsFormId, maptext);
        //获取变更统计表的路径
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setProjectId(pDto.getId());
        supervisorFile.setType("095");
        supervisorFile.setSpmId(pDto.getSpmId());
        /*    supervisorFile.setPcId(pFbId);*/
        SupervisorFile AoFile = supervisorFileService.selectOne(supervisorFile);
        if (!isNull(AoFile)) {
            String AsTargetFileName = AoFile.getUrl();
            if (StringUtil.isNotBlank(AsTargetFileName)) {
                HashMap mapprojectinfo = doProjectInfo(pDto.getId(), pFbId);
                /*将提取的变更单中的文字 追加到统计表中*/
                WordUtil.saveBgtjList(mapprojectinfo, maptext, AsTargetFileName);
            }
        }
        return maptext;
    }

    /**
     * @param projectId
     * @param pFbId
     * @Author:zhaoyongke
     * @Description: 获取项目基本信息
     * @Date:22:08 2021/1/10
     */
    public HashMap doProjectInfo(String projectId, String pFbId) {
        SupervisorProjectDTO supervisorProjectdto = new SupervisorProjectDTO();
        //查询项目
        supervisorProjectdto.setId(projectId);
        List<SupervisorProjectDTO> projectlist = supervisorProjectService.selectSupervisorProject(supervisorProjectdto);
        if (projectlist.size() > 0) {
            supervisorProjectdto = projectlist.get(0);
        }

        HashMap mapproject = new HashMap();
        mapproject.put("projectName", supervisorProjectdto.getProjectName());
        mapproject.put("yzCompany", supervisorProjectdto.getOwerCompany());
        mapproject.put("jlCompany", supervisorProjectdto.getSupervisorCompanyName());
        //查询承建单位
        ProjectContract contract = projectContractService.selectByPrimaryKey(pFbId);
        String fbcode = contract.getCode();
        ProjectUnitConstruction construction = new ProjectUnitConstruction();
        construction.setSupervisorProjectId(projectId);
        construction.setConstructionSubContractNumber(fbcode);
        List<ProjectUnitConstruction> unitConstructionlist = projectUnitConstructionService.select(construction);
        ProjectUnitConstruction cjunit = null;
        if (unitConstructionlist.size() > 0) {
            cjunit = unitConstructionlist.get(0);
        }
        if (cjunit != null) {
            String cjCompany = cjunit.getUnitConstruction();
            if (cjCompany != null && StringUtil.isNotBlank(cjCompany)) {
                mapproject.put("cjCompany", cjCompany);
            } else {
                mapproject.put("cjCompany", "");
            }
        }

        return mapproject;
    }

    /**
     * @param aiTableIndex
     * @param asFormId
     * @param aiRowCnt
     * @param rowdata
     * @Author:Zhangshuo
     * @Description:解析文件数据保存到FormData表中
     * @Date:22:18 2020-12-08
     */
    private void parsingFileDataToFormData(int aiTableIndex, String asFormId, int aiRowCnt, List<String> rowdata) {
        int AiColCnt = rowdata.size();
        JSONObject AjsItem = new JSONObject();
        for (int i = 0; i < AiColCnt; i++) {
            AjsItem.put("Data" + (i + 1), rowdata.get(i));
        }
        SupervisorProjectFormsData supervisorProjectFormsData = JSONObject.toJavaObject(AjsItem, SupervisorProjectFormsData.class);
        supervisorProjectFormsData.setSpfId(asFormId);
        supervisorProjectFormsData.setTableIndex(aiTableIndex);
        supervisorProjectFormsData.setTableRow(aiRowCnt);
        supervisorProjectFormsData.setTableCos(AiColCnt);
        supervisorProjectFormsDataService.insertSelective(supervisorProjectFormsData);
    }

    /**
     * @param psFileName
     * @param dto
     * @param asFormId
     * @Author:Zhangshuo
     * @Description:解析文件数据到Form表中
     * @Date:22:18 2020-12-08
     */
    private void parsingFileDataToForm(String psFileName, SupervisorProjectDTO dto, String asFormId) {
        //给Form表增加实例
       SupervisorProjectForms AoForms = new SupervisorProjectForms();
       String fbId= dto.getFbId();
       String  fbcode="";
       if(StringUtil.isNotBlank(fbId)){
           ProjectContract contract = projectContractService.selectByPrimaryKey(fbId);
           if(contract!=null){
               fbcode = contract.getCode();
           }
           AoForms.setFbCode(fbcode);
       }else{
           AoForms.setFbCode(dto.getFbCode());
       }
        AoForms.setSpfId(asFormId);
        AoForms.setSpfPrjid(dto.getId());
        AoForms.setSpfStaid(dto.getStageId());

        AoForms.setSpfMilid(dto.getSpmId());

        AoForms.setPcId(dto.getFbId());
        AoForms.setSaveFilePath(psFileName);
        supervisorProjectFormsService.insertSelective(AoForms);
    }

    /**
     * @param psFileName
     * @param dto
     * @param asFormId
     * @param datamap
     * @Author:zhaoyongke
     * @Description: 保存变更数据到form
     * @Date:13:57 2021/1/13
     */
    private void saveBgdDataToForm(String psFileName, SupervisorProjectDTO dto, String asFormId, Map datamap) {
        //给Form表增加实例
        SupervisorProjectForms AoForms = new SupervisorProjectForms();
        AoForms.setSpfId(asFormId);
        AoForms.setSpfPrjid(dto.getId());
        AoForms.setSpfStaid(dto.getStageId());
        AoForms.setSpfMilid(dto.getSpmId());
        AoForms.setFbCode(dto.getFbCode());
        AoForms.setPcId(dto.getFbId());
        AoForms.setSpfF1(datamap.get("reason") + "");
        AoForms.setSpfF2(datamap.get("name") + "");
        AoForms.setSpfF3(datamap.get("before") + "");
        AoForms.setSpfF4(datamap.get("after") + "");
        AoForms.setSpfF5(datamap.get("money") + "");
        AoForms.setSpfF6(datamap.get("dh") + "");
        AoForms.setSaveFilePath(psFileName);
        supervisorProjectFormsService.insertSelective(AoForms);
    }

    /**
     * @param dto
     * @param spmid     里程ID
     * @param projectid 项目ID
     * @param fbId      分包ID
     * @Author:Zhangshuo
     * @Description:
     * @Date:12:34 2020/12/4
     */
    private UploadType getFileUploadType(SupervisorProjectDTO dto, String spmid, String projectid, String fbId, String psFileStuffix, String pUploadType) throws Exception {
        SupervisorProject AoSupervisorProject = supervisorProjectService.selectByPrimaryKey(projectid);
        String AsType = dto.getType();
        ProjectContract AoPackage = new ProjectContract();
        if (null != fbId && !"".equals(fbId)) {
            AoPackage = projectContractService.selectByPrimaryKey(fbId);
        }
        String AsFbCode = AoPackage.getCode();
        BaseDict AoBaseDict = DictUtil.getDictByCode(DictTypes.WJ, AsType + (StringUtil.isBlank(pUploadType) ? "" : pUploadType));
        String AsFpId = AoBaseDict.getBadtLevel2();

        if (StringUtil.isNotBlank(AsFpId)) {
            SupervisorFile AoSupervisorFile = new SupervisorFile();
            if (("040".equals(AsType) || "093".equals(AsType) || "036".equals(AsType) || "037".equals(AsType) || "106".equals(AsType) || "108".equals(AsType) || "109".equals(AsType) || "087".equals(AsType) || "088".equals(AsType)) && ("002".equals(pUploadType))) {
                /*附件通过parentId查询*/
                AoSupervisorFile.setParentId(dto.getParentId());
            } else {
                AoSupervisorFile.setProjectId(projectid);
                AoSupervisorFile.setSpmId(spmid);
                AoSupervisorFile.setPcId(fbId);
                AoSupervisorFile.setType(AsType);
            }
            UploadType uploadType = prepareFileUploadType(AoSupervisorProject, AsType, AsFbCode, AsFpId, psFileStuffix, dto.getFileCount(), AoSupervisorFile, pUploadType, dto.getPositionName());
            return uploadType;
        } else {
            throw new Exception("文件类型：" + AsType + "，未发现配置存储路径，请到数据字典中配置。");
        }
    }

    /**
     * @param
     * @Author:Zhangshuo
     * @Description:
     * @Date:10:51 2020/12/4
     */
    private UploadType prepareFileUploadType(SupervisorProject poSupervisorProject, String psFileType, String psFbCode, String psFpId, String psFileStuffix, int piFileCount, SupervisorFile poSupervisorFile, String pUploadType, String pPositionName) {
        return prepareUploadType(0, poSupervisorProject.getProjectName(), psFileType, psFbCode, psFpId, psFileStuffix, piFileCount, poSupervisorFile, pUploadType, pPositionName);
    }

    /**
     * @param request
     * @Author:zhaoyongke
     * @Description: 导航到form 表单 页面
     * @Date:14:53 2020/11/14
     */
    @GetMapping(value = "addWjForm")
    public String addWjForm(Model model, HttpServletRequest request) {
        String type = request.getParameter("type");// 文件类型
        String fs_status = request.getParameter("fs_status");// 状态
        // 获取项目章
        List<BaseDict> xmzlist = baseDictService.selectByTypeCode("JLZ001");
        model.addAttribute("xmzlist", xmzlist);
        return "/supervisor/projectManager/schy-xmyzsq";
    }


    /**
     * @param ids
     * @Author:zhaoyongke
     * @Description:删除附件
     * @Date:14:55 2020/11/20
     */
    @RequestMapping(value = "/deleteFile", method = RequestMethod.POST)
    @ResponseBody
    public JsonUtil deleteFile(String ids, String type) {
        List<String> list = Tutil.split(ids);
        JsonUtil re = new JsonUtil();
        try {
            for (int i = 0; i < list.size(); i++) {
                SupervisorFile fileselect = new SupervisorFile();
                fileselect.setId(list.get(i));
                List<SupervisorFile> fileselectlist = supervisorFileService.select(fileselect);
                //文件类型
                String wjcode = fileselectlist.get(0).getType();
                String createType = fileselectlist.get(0).getCreateType();
                if("1".equals(createType)){
                    re.setMsg("从供需移动过来的文件，不允许删除!");
                    re.setFlag(false);
                    return re;
                }
                /*获取该文件的流程状态*/
                Boolean lcstatus = getLcStatus(fileselectlist, wjcode, "001");
                if (!lcstatus) {
                    re.setMsg("流程进行中，不允许删除!");
                    re.setFlag(false);
                    return re;
                }
                SupervisorFile deletefile = supervisorFileService.selectByPrimaryKey(list.get(i));
                String deletePrId = deletefile.getProjectId();
                String role = sysUserService.getUserRole(deletePrId);
                if ("xmjl".equals(role) || "cj".equals(role) || "zjlgcs".equals(role) || "jlgcs".equals(role)) {
                    if ("cj".equals(role) || "jlgcs".equals(role)) {
                        /*承建单位*/
                        //监理工程师 只删除自己的
                        String uplaodUser = deletefile.getCreateBy();
                        //如果该文件不是自己上传的
                        if (!CommonUtil.getUserId().equals(uplaodUser)) {
                            re.setMsg("您没有权限操作!");
                            re.setFlag(false);
                            return re;
                        }
                    }

                } else {
                    re.setMsg("您没有权限操作!");
                    re.setFlag(false);
                    return re;
                }
                //监理方上传的文件，承建方应不能删除
            /*    SupervisorFile deletefile=supervisorFileService.selectByPrimaryKey(list.get(i));
                String projectId=deletefile.getProjectId();
                SupervisorProject project=supervisorProjectService.selectByPrimaryKey(projectId);
                String xmjl=project.getProjectManagerPerson();
                String userId=CommonUtil.getUserId();
                if(!userId.equals(xmjl)){
                    //不是項目经理操作删除按钮
                    String uplaodUser=deletefile.getCreateBy();
                    //如果该文件不是自己上传的
                    if(!userId.equals(uplaodUser)){
                        re.setMsg("您没有权限删除!");
                        re.setFlag(false);
                        return re;
                    }
                }*/

                supervisorFileService.deleteByPrimaryKey(list.get(i));
                //查询子文件
                SupervisorFile file = new SupervisorFile();
                file.setParentId(list.get(i));
                List<SupervisorFile> filelist = supervisorFileService.select(file);
                for (int y = 0; y < filelist.size(); y++) {
                    String zfileId = filelist.get(y).getId();
                    supervisorFileService.deleteByPrimaryKey(zfileId);
                }

                //删除货物清单对应的数据
                if ("hwqd".equals(type)) {
                    String pcId = deletefile.getPcId();
                    Example example = new Example(SupervisorProjectForms.class);
                    Example.Criteria criteria = example.createCriteria();
                    criteria.andEqualTo("spfPrjid", deletePrId);
                    if(StringUtil.isNotBlank(pcId)){
                        ProjectContract contract = projectContractService.selectByPrimaryKey(pcId);
                        if(contract!=null){
                            String  fbcode = contract.getCode();
                            criteria.andEqualTo("fbCode", fbcode);
                        }
                    }
                    criteria.andEqualTo("spfMilid", deletefile.getSpmId());
                    criteria.andLike("saveFilePath", "%货物清单%");
                    List<SupervisorProjectForms> lists = supervisorProjectFormsService.selectByExample(example);
                    for (SupervisorProjectForms forms : lists) {
                        SupervisorProjectFormsData data = new SupervisorProjectFormsData();
                        data.setSpfId(forms.getSpfId());
                        supervisorProjectFormsDataService.delete(data);
                        supervisorProjectFormsService.deleteByPrimaryKey(forms.getSpfId());
                    }
                }

            }
            re.setMsg("删除成功");
            re.setFlag(true);
        } catch (
                Exception e) {
            re.setMsg("删除失败!" + e.getMessage());
            re.setFlag(false);
            e.printStackTrace();
        }
        return re;
    }

    /**
     * @param stageid
     * @param projectId
     * @Author:zhaoyongke
     * @Description: 查询里程碑--根据项目阶段id  项目详情左侧菜单
     * @Date:10:48 2020/11/6
     */
    @RequestMapping(value = "/queryMilePost", method = RequestMethod.GET)
    @ResponseBody
    public JsonUtil queryMilePost(String stageid, String projectId) {
        JsonUtil re = new JsonUtil();
        try {
            SupervisorProjectMilepostDTO su = new SupervisorProjectMilepostDTO();
            su.setSupervisorProjectStageId(stageid);
            su.setProjectId(projectId);
            List<SupervisorProjectMilepostDTO> list = supervisorProjectMilepostService.selectProjectmilepost(su);
            re.setData(list);
            re.setMsg("获取成功");
            re.setFlag(true);
        } catch (Exception e) {
            re.setMsg("获取失败!" + e.getMessage());
            re.setFlag(false);
            e.printStackTrace();
        }

        return re;
    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 查询文件列表
     * @Date:9:58 2020/11/27
     */
    @RequestMapping(value = "/showFileList", method = RequestMethod.GET)
    @ResponseBody
    public ReType showFileList(SupervisorProjectDTO dto, Model model, String page, String limit) {

        ReType re = new ReType();
        String uploadType = dto.getUploadType();
        SupervisorFile file = new SupervisorFile();
        List<SupervisorFile> list = null;
        if ("088".equals(dto.getType()) || "109".equals(dto.getType())) {
            Example ex = new Example(SupervisorFile.class);
            Example.Criteria cr = ex.createCriteria();
            cr.andNotEqualTo("type", "113");
            cr.andEqualTo("parentId", dto.getParentId());
            list = supervisorFileService.selectByExample(ex);
        } else {
            if ("002".equals(uploadType)) {// 每个文件下面有图片 根据 parentId 查询  例如 检查旁站 每个文件下的图片列表
                file.setParentId(dto.getParentId());
            } else {//
                file.setProjectId(dto.getProjectId());
                file.setSpmId(dto.getSpmId());
                file.setPcId(dto.getFbId());
                file.setType(dto.getType());
                // 2022年6月2日10:44:51新增 查询开箱检验下的附件 需要根据父id查询
                if ("040".equals(dto.getType()) && "21".equals(uploadType)){
                    file.setParentId(dto.getParentId());
                }
            }
            list = supervisorFileService.select(file);
//        for (int i = 0; i < list.size(); i++) {
//            String url = list.get(i).getUrl();
//            //获取文件名称
//            if (StringUtil.isNotBlank(url)) {
//                String urlz = FilePathUtil.getFileName(url);
//                list.get(i).setUrl(urlz);
//            }
//        }
        }
        re.setData(list);
        return re;
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:（1）招标阶段------>(1)招标文件
     * @Date:10:01 2020/11/6
     */
    @Guide
    @GetMapping(value = "zbwj")
    public String zbwj(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id

        //查询项目
        SupervisorProject supervisorProject = new SupervisorProject();
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);

        // 查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);

        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);

        // 查询文件
        SupervisorFile supervisorFile = new SupervisorFile();
        // 通过项目id 里程id 查询文件
        //（1）监理招标文件
        supervisorFile.setType("001");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);

        List<SupervisorFile> listjlzb = supervisorFileService.select(supervisorFile);
        // (2)监理投标文件
        supervisorFile.setType("002");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listjltb = supervisorFileService.select(supervisorFile);

        // 查询分包表
        List<ProjectContract> listcjht_fb = getProjectContracts(id, "001");


        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);
        request.setAttribute("lcdto", milepost);
        request.setAttribute("stagedto", stage);
        request.setAttribute("listjlzb", listjlzb);
        request.setAttribute("listjltb", listjltb);
        request.setAttribute("listcjht_fb", listcjht_fb);// 分包表
        return "/supervisor/projectManager/zbwj";
    }

    /**
     * @param id
     * @Description:
     * @Author:Zhangshuo
     * @Date:15:06 2020-12-19
     */
    private List<ProjectContract> getProjectContracts(String id, String type) {
        ProjectContractDTO projectContract = new ProjectContractDTO();
        projectContract.setProjectId(id);
        String AsUserId = CommonUtil.getUserId();
        //业主单位项目负责人和承建单位项目经理只查看自己负责的
        String userRole = sysUserService.getUserRole(id);
        if (StringUtils.isNotBlank(userRole)) {
            if ("yz".equals(userRole)) {
                projectContract.setProjectLeader(AsUserId);
            } else if ("cj".equals(userRole)) {
                projectContract.setProjectManager(AsUserId);
            }
        }
        // 20210707 zhaoyongke  修改：到货验收和合同清单 页面的分包页签 需要根据 创建项目 选择的是否有到货验收来显示
        if ("002".equals(type)) {
            projectContract.setInspectionMerchandise("1");
        } else {
            projectContract.setInspectionMerchandise(null);
        }

        List<ProjectContract> listcjht_fb = projectContractService.getProjectPackageByRole(projectContract);
        return listcjht_fb;
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: （1）招标阶段------>(2)招标合同
     * @Date:13:25 2020/11/5
     */
    @Guide
    @GetMapping(value = "zbht")
    public String zbht(Model model, HttpServletRequest request) {


        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id

        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);

        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);

        // 通过项目id 里程id 查询文件
        //（1）监理合同文件
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setType("005");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listjlht = supervisorFileService.select(supervisorFile);

        // 查询分包表
        List<ProjectContract> listcjht_fb = getProjectContracts(id, "001");
        //货物清单  20210207

        List<ProjectContract> listcjht_qd = getProjectContracts(id, "002");

        // (2)城建合同文件  不需要分包展示
        supervisorFile.setType("006");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listcjht = supervisorFileService.select(supervisorFile);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);
        request.setAttribute("lcdto", milepost);
        request.setAttribute("stagedto", stage);
        request.setAttribute("listjlht", listjlht);// 监理合同文件
        request.setAttribute("listcjht", listcjht);//城建合同文件
        request.setAttribute("listcjht_fb", listcjht_fb);//城建合同文件(分包表)
        request.setAttribute("listcjht_qd", listcjht_qd);//城建合同文件(分包表)
        //
        if (listcjht_qd != null) {
            int size = listcjht_qd.size();
            if (size > 0) {
                request.setAttribute("isshowqd", "1");
            }
        }
        //纯软件 项目不能用纯软件监理没有实施图纸条目  20210811 修改
        String projectType = project.getProjectType();
        if ("002".equals(projectType)) {
            request.setAttribute("isshowsgtz", "0");
        } else {
            request.setAttribute("isshowsgtz", "1");
        }

        return "/supervisor/projectManager/zbht";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:（1）招标阶段------>(3)首次会议 文件类型（1） 监理规划/监理工作规范  007  （2）监理项目用章授权书 008  （3）会议纪要 009  （4）项目通讯录 010
     * @Date:11:05 2020/11/6
     */
    @Guide
    @GetMapping(value = "schy")
    public String schy(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);

        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);


        // 通过项目id 里程id 查询文件
        //（1）监理规划  007
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setType("007");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listjlgh_file = supervisorFileService.select(supervisorFile);
        //（2）监理工作规范   008
        supervisorFile.setType("008");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listjlgzgf_file = supervisorFileService.select(supervisorFile);


        //（3）监理项目用章授权书   009
        supervisorFile.setType("009");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listjlsq_file = supervisorFileService.select(supervisorFile);
        //（3）会议纪要   010
        supervisorFile.setType("010");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listjlhyi_file = supervisorFileService.select(supervisorFile);
        //（4） 项目通讯录   011
        supervisorFile.setType("011");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listjltxl_file = supervisorFileService.select(supervisorFile);
        // 处理完成按钮  流程正在进行 完成按钮至成灰色
        getButFinishStatus(listjlgh_file, "007", request);
        getButFinishStatus(listjlgzgf_file, "008", request);
        getButFinishStatus(listjlsq_file, "009", request);
        getButFinishStatus(listjlhyi_file, "010", request);
        getButFinishStatus(listjltxl_file, "011", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listjlgh_file", listjlgh_file);//（1） 监理规划  007
        request.setAttribute("listjlgzgf_file", listjlgzgf_file);//（2） 监理工作规范  008
        request.setAttribute("listjlsq_file", listjlsq_file);// 3）监理项目用章授权书 009
        request.setAttribute("listjlhyi_file", listjlhyi_file);// （4）会议纪要 010
        request.setAttribute("listjltxl_file", listjltxl_file);// (5）项目通讯录 011
        return "/supervisor/projectManager/schy";
    }

    /**
     * @param filelist
     * @param wjcode
     * @param request
     * @Author:zhaoyongke
     * @Description:获取按钮状态
     * @Date:15:50 2020/12/23
     */
    public void getButFinishStatus(List<SupervisorFile> filelist, String wjcode, HttpServletRequest request) {
        // 判断流程是否进行完
        Boolean isxs = getLcStatus(filelist, wjcode, "");
        request.setAttribute("finish_status_" + wjcode, isxs);
    }

    /**
     * @param filelist
     * @param wjcode
     * @Author:zhaoyongke
     * @Description: 判断流程是否结束
     * @Date:14:55 2020/12/31
     */
    public Boolean getLcStatus(List<SupervisorFile> filelist, String wjcode, String type) {
        BaseDict dict = DictUtil.getDictByCode(DictTypes.WJ, wjcode);
        String lcsl = dict.getBadtLevel3();
        Boolean isxs = true;
        if (StringUtil.isNotBlank(lcsl)) {
            // 流程都结束后才可以显示
            //流程状态0 内部未发起流程1 内部进行中 2 内部流程审核通过3内部流程审核不通过4外部流程进行中5外部流程审核通过（归档）6 外部流程审核不通过
            for (int i = 0; i < filelist.size(); i++) {
                SupervisorFile file = filelist.get(i);
                //流程状态
                String lcstatus = file.getLcStatus();
                // 3 包含外部流和内部流程 2 只包含外部流程   1 只包含内部流程
                if ("3".equals(lcsl) || "2".equals(lcsl)) {
                    if ("001".equals(type)) {
                        //  20210821 驳回后可以删除  内部驳回后的状态为 0
                        if("3".equals(lcsl)){
                            if("0".equals(lcstatus)){
                                isxs = true;// 内部流程驳回可以删除
                                break;
                            }
                        }else if("2".equals(lcsl)){
                            if("2".equals(lcstatus)){
                                isxs = true;// 外部流程驳回可以删除
                                break;
                            }

                        }
                        if (!"3".equals(lcstatus) && !"5".equals(lcstatus) && !"6".equals(lcstatus) && lcstatus != null && !"".equals(lcstatus)) {
                            // 流程进行 不能删除
                            isxs = false;
                            break;
                        }
                    } else {
                        // 20210810 修改为 外部流程任何状态下都可以点击完成 ，内部流程 必须走完才能点击完成

                        String projectId = file.getProjectId();
                        String role = sysUserService.getUserRole(projectId);
                        if ("zjlgcs".equals(role)) {
                            isxs = true;
                            break;
                        }
                        if ("2".equals(lcsl)) {
                            isxs = true;
                            break;
                            // 外部流程 不需要判断流程状态就可以点击完成
                        } else if ("3".equals(lcsl)) {
                            // 包含内外部流程的 只要内部流程审核通过就可以点击完成

                            if (StringUtil.isBlank(lcstatus) || "0".equals(lcstatus) || "1".equals(lcstatus) || "3".equals(lcstatus)) {
                                isxs = false;
                                break;
                            }
                        }
//                        if (!"5".equals(lcstatus)) {
//                            // 流程未结束  不能点击完成按钮 按钮 隐藏
//                            isxs = false;
//                            if("4".equals(lcstatus) ){
//                                //流程进行中,判断该操作人是不是项目的总监理工程师:
//                                String actor = CommonUtil.getUserId();
//                                String projectId = file.getProjectId();
//                                if(StringUtils.isNotBlank(projectId)){
//                                    SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
//                                    if(null != project){
//                                        //项目的总监理工程师:
//                                        String supervisorEngineer = project.getSupervisorEngineer();
//                                        if(actor.equals(supervisorEngineer)){
//                                            isxs = true;
//                                        }
//                                    }
//                                }
//                            }
//                            break;
//                        }
                    }

                } else if ("1".equals(lcsl)) {
                    if ("001".equals(type)) {
                        if("0".equals(lcstatus)){
                            isxs = true;// 内部流程驳回可以删除
                            break;
                        }
                        if (!"2".equals(lcstatus) && !"3".equals(lcstatus) && lcstatus != null && !"".equals(lcstatus)) {
                            // 流程进行 不能删除
                            isxs = false;
                            break;
                        }
                    } else {
                        String projectId = file.getProjectId();
                        String role = sysUserService.getUserRole(projectId);
                        //20211120  zhaoyongke 针对测试报告的第 20 项修改，将总监理工程师 注释掉
//                        if ("zjlgcs".equals(role)) {
//                            isxs = true;
//                            break;
//                        }
                        if (!"2".equals(lcstatus)) {
                            // 流程未结束  不能点击完成按钮 按钮 隐藏
                            isxs = false;
                            break;
                        }
                    }

                }

            }
        }
        return isxs;
    }


    /**
     * @param model   012   项目经理授权书  013  项目人员名单  014   项目章授权书
     * @param request
     * @Author:zhaoyongke
     * @Description: 开工准备
     * @Date:9:26 2020/11/9
     */
    @Guide
    @GetMapping(value = "kgzb")
    public String kgzb(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);


        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);


        // 通过项目id 里程id 查询文件
        //（1）项目经理授权书  012
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setType("012");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listxmsq_file = supervisorFileService.select(supervisorFile);
        //（2）项目人员名单   013
        supervisorFile.setType("013");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listxmry_file = supervisorFileService.select(supervisorFile);


        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        // (3)项目章授权书 不需要分包展示
        supervisorFile.setType("014");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listsqs_file = supervisorFileService.select(supervisorFile);
        // 完成按钮是否至灰色
        getButFinishStatus(listxmsq_file, "012", request);
        getButFinishStatus(listxmry_file, "013", request);
        getButFinishStatus(listsqs_file, "014", request);


        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listxmsq_file", listxmsq_file);//（1） 项目经理授权书   012
        request.setAttribute("listxmry_file", listxmry_file);//（2） 项目人员名单  013
        request.setAttribute("listsqs_fb", listsqs_fb);// 3）项目章授权书 014  分包的情况
        request.setAttribute("listsqs_file", listsqs_file);// 3）项目章授权书 014   不分包的情况
        return "/supervisor/projectManager/kgzb";
    }

    /**
     * @param model   015  开工申请    016  开工通知
     * @param request
     * @Author:zhaoyongke
     * @Description: 开工
     * @Date:10:38 2020/11/9
     */
    @Guide
    @GetMapping(value = "kg")
    public String kg(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id

        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);


        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();


        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        //(1) 开工申请  015
        supervisorFile.setType("015");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listkgsq_file = supervisorFileService.select(supervisorFile);
        //（2）开工通知   016
        supervisorFile.setType("016");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listkgtz_file = supervisorFileService.select(supervisorFile);

        getButFinishStatus(listkgsq_file, "015", request);
        getButFinishStatus(listkgtz_file, "016", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listkgsq_file", listkgsq_file);//（1） 开工申请
        request.setAttribute("listkgtz_file", listkgtz_file);//（2） 开工通知

        return "/supervisor/projectManager/kg";
    }


    /**
     * @param model   017  计划进度    018  实施方案   019  实施图纸  020 实施方案专家评审意见和评审会议纪要  021  监理审核报告
     * @param request
     * @Author:zhaoyongke
     * @Description: 设计阶段-----  计划和方案
     * @Date:11:46 2020/11/9
     */
    @Guide
    @GetMapping(value = "jhfan")
    public String jhfan(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id

        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        // 计划进度
        supervisorFile.setType("017");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listjhjd_file = supervisorFileService.select(supervisorFile);
        // 实施方案
        supervisorFile.setType("018");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> ywfalist_file = supervisorFileService.select(supervisorFile);


        //（6）评审会议纪要   065
        supervisorFile.setType("065");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listhyjy_file = supervisorFileService.select(supervisorFile);
        //（6）监理审核报告   021
        supervisorFile.setType("021");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listshbg_file = supervisorFileService.select(supervisorFile);

        getButFinishStatus(listjhjd_file, "017", request);
        getButFinishStatus(ywfalist_file, "018", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        // 纯软件监理没有实施图纸条目
        String projectType = project.getProjectType();
        if ("002".equals(projectType)) {
            //实施图纸条目
            request.setAttribute("isshow", "0");
        } else {
            request.setAttribute("isshow", "1");
        }
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listhyjy_file", listhyjy_file);//（4） 评审会议纪要
        request.setAttribute("listshbg_file", listshbg_file);//（5） 监理审核报告
        return "/supervisor/projectManager/jhfan";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 监理实施细则    022  监理实施细则
     * @Date:14:31 2020/11/9
     */
    @Guide
    @GetMapping(value = "jlssxz")
    public String jlssxz(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        ProjectContract projectContract = new ProjectContract();
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listssxz_file = null;// 监理实施细则
        //(1) 022  监理实施细则
        supervisorFile.setType("022");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listssxz_file = supervisorFileService.select(supervisorFile);

        // 完按钮
        getButFinishStatus(listssxz_file, "022", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listssxz_file", listssxz_file);//（1） 计划进度
        return "/supervisor/projectManager/jlssxz";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 设计阶段----- 需求文件----> 023 需求调研报告 024 需求规格说明书 025 需求专家评审意见 026  评审会议纪要 027    监理审核报告
     * @Date:16:27 2020/11/9
     */
    @Guide
    @GetMapping(value = "xqwj")
    public String xqwj(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listxqty_file = null;// 需求调研报告
        List<SupervisorFile> listpsyj_file = null;// 需求专家评审意见

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 024
        supervisorFile.setType("024");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listsms_file = supervisorFileService.select(supervisorFile);


        // 026 评审会议纪要
        supervisorFile.setType("026");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listhyjy_file = supervisorFileService.select(supervisorFile);
        //027 监理审核报告
        supervisorFile.setType("027");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listshbg_file = supervisorFileService.select(supervisorFile);

        getButFinishStatus(listsms_file, "024", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listxqty_file", listxqty_file);// 023 需求调研报告
        request.setAttribute("listsms_file", listsms_file);// 024 需求规格说明书
        request.setAttribute("listpsyj_file", listpsyj_file);// 025 需求专家评审意见
        request.setAttribute("listhyjy_file", listhyjy_file);// 026 评审会议纪要
        request.setAttribute("listshbg_file", listshbg_file);// 027 监理审核报告
        return "/supervisor/projectManager/xqwj";

    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 设计文件  ------   028设计文档   029设计专家评审意见  030 评审会议纪要  031 监理审核报告
     * @Date:19:03 2020/11/9
     */
    @Guide
    @GetMapping(value = "sjwj")
    public String sjwj(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listsjwd_file = null;//   028 设计文档
        List<SupervisorFile> listpsyj_file = null;//  029 设计专家评审意见

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 028  评审会议纪要
        supervisorFile.setType("028");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listsjwd_file = supervisorFileService.select(supervisorFile);


        // 030  评审会议纪要
        supervisorFile.setType("030");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listhyjy_file = supervisorFileService.select(supervisorFile);
        // 031  监理审核报告
        supervisorFile.setType("031");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listshbg_file = supervisorFileService.select(supervisorFile);
        // 完按钮
        getButFinishStatus(listsjwd_file, "028", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listsjwd_file", listsjwd_file);//  028  设计文档
        request.setAttribute("listpsyj_file", listpsyj_file); // 029  设计专家评审意见
        request.setAttribute("listhyjy_file", listhyjy_file);//  030  评审会议纪要
        request.setAttribute("listshbg_file", listshbg_file); // 031  监理审核报告
        return "/supervisor/projectManager/sjwj";

    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 设计阶段---------》深化设计文件   032 深化设计文件（含施工图纸）  033 深化专家评审意见   034 评审会议纪要  035 监理审核报告
     * @Date:20:56 2020/11/9
     */
    @Guide
    @GetMapping(value = "shsjwj")
    public String shsjwj(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listsjwj_file = null;//  032 深化设计文件（含施工图纸）
        List<SupervisorFile> listzjps_file = null;//  033 深化专家评审意见
        List<SupervisorFile> listhyjy_file = null; // 034 评审会议纪要
        List<SupervisorFile> listshbg_file = null; // 035 监理审核报告

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        //  032 深化设计文件（含施工图纸）
        supervisorFile.setType("032");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listsjwj_file = supervisorFileService.select(supervisorFile);
        // 033  深化专家评审意见
        supervisorFile.setType("033");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listzjps_file = supervisorFileService.select(supervisorFile);

        // 034 评审会议纪要
        supervisorFile.setType("034");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listhyjy_file = supervisorFileService.select(supervisorFile);
        //  035 监理审核报告
        supervisorFile.setType("035");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listshbg_file = supervisorFileService.select(supervisorFile);

        // 完按钮
        getButFinishStatus(listsjwj_file, "032", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listsjwj_file", listsjwj_file);//  032 深化设计文件（含施工图纸）
        request.setAttribute("listzjps_file", listzjps_file); // 033 深化专家评审意见
        request.setAttribute("listhyjy_file", listhyjy_file);  // 034 评审会议纪要
        request.setAttribute("listshbg_file", listshbg_file);   //  035 监理审核报告
        return "/supervisor/projectManager/shsjwj";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:检查旁站
     * @Date:9:23 2020/11/27
     */
    @Guide
    @GetMapping(value = "ss_jcpz")
    public String ss_jcpz(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据

        return "/supervisor/projectManager/ss_jcpz";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 实施阶段-----到货验收
     * @Date:17:27 2020/11/18
     */
    @Guide
    @GetMapping(value = "dhys")
    public String dhys(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");//
        ProjectContract projectContract = new ProjectContract();
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(supervisorProject);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);

        //查询文件数据
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> AlistFiles = supervisorFileService.select(supervisorFile);
        //设备报备表
        supervisorFile.setType("038");
        List<SupervisorFile> listsbbb_file = supervisorFileService.select(supervisorFile);
        //材料设备进场检验报告
        supervisorFile.setType("039");
        List<SupervisorFile> listcl_file = supervisorFileService.select(supervisorFile);
        //序列号验证记录
        supervisorFile.setType("042");
        List<SupervisorFile> listxl_file = supervisorFileService.select(supervisorFile);
        //到货验收图片
        supervisorFile.setType("043");
        List<SupervisorFile> listdhtp_file = supervisorFileService.select(supervisorFile);
        //合同对比报告
        supervisorFile.setType("044");
        List<SupervisorFile> listht_file = supervisorFileService.select(supervisorFile);
        //到货验收报告
        supervisorFile.setType("045");
        List<SupervisorFile> listdhbg_file = supervisorFileService.select(supervisorFile);


        //查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "002");
        for (int i = 0; i < listsqs_fb.size(); i++) {
            String fbId = listsqs_fb.get(i).getId();
            request.setAttribute("fbId", fbId);
            List<SupervisorFile> list038file = new ArrayList<>();
            List<SupervisorFile> list039file = new ArrayList<>();
            ;
            for (int j = 0; j < listsbbb_file.size(); j++) {
                String pcId = listsbbb_file.get(j).getPcId();
                if (fbId.equals(pcId)) {
                    list038file.add(listsbbb_file.get(j));
                }
            }
            for (int j = 0; j < listcl_file.size(); j++) {
                String pcId = listcl_file.get(j).getPcId();
                if (fbId.equals(pcId)) {
                    list039file.add(listcl_file.get(j));
                }
            }
            // 完成按钮 是针对每个分包的完成按钮
            getButFinishStatus(list038file, "038", request);
            getButFinishStatus(list039file, "039", request);
        }
        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);

        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listsbbb_file", listsbbb_file);
        request.setAttribute("listcl_file", listcl_file);
        request.setAttribute("listxl_file", listxl_file);
        request.setAttribute("listdhtp_file", listdhtp_file);
        request.setAttribute("listht_file", listht_file);
        request.setAttribute("listdhbg_file", listdhbg_file);

        return "/supervisor/projectManager/dhys";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:
     * @Date:10:19 2020/11/27
     */
    @Guide
    @GetMapping(value = "ss_ybys")
    public String ss_ybys(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        ProjectContract projectContract = new ProjectContract();
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setType("046");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listybysrecord_file = supervisorFileService.select(supervisorFile);
        getButFinishStatus(listybysrecord_file, "046", request);

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        return "/supervisor/projectManager/ss_ybys";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 实施阶段-----检验检测
     * @Date:10:22 2020/11/19
     */
    @Guide
    @GetMapping(value = "jyjc")
    public String jyjc(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);

        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listhyjy_file = null;// 检验报告
        List<SupervisorFile> listshbg_file = null;// 检测报告

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        //（2）检验报告
        supervisorFile.setType("073");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listhyjy_file = supervisorFileService.select(supervisorFile);
        //（3）检测报告
        supervisorFile.setType("074");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listshbg_file = supervisorFileService.select(supervisorFile);

        getButFinishStatus(listhyjy_file, "073", request);
        getButFinishStatus(listshbg_file, "074", request);


        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据

        request.setAttribute("listhyjy_file", listhyjy_file);//检验报告
        request.setAttribute("listshbg_file", listshbg_file);//检测报告
        return "/supervisor/projectManager/jyjc";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 实施阶段-----计划和方案
     * @Date:11:46 2020/11/9
     */
    @Guide
    @GetMapping(value = "ssjhfan")
    public String jsshfan(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        ProjectContract projectContract = new ProjectContract();
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);

        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listjhjd_file = null;// 进度计划
        List<SupervisorFile> ywfalist_file = null;// 运维方案
        List<SupervisorFile> listhyjy_file = null;// 实施方案专家评审意见和评审会议纪要
        List<SupervisorFile> listshbg_file = null;// 监理审核报告


        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 计划进度
        supervisorFile.setType("067");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjhjd_file = supervisorFileService.select(supervisorFile);
        // 运维方案
        supervisorFile.setType("068");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        ywfalist_file = supervisorFileService.select(supervisorFile);

        //（4）运维专家评审意见和评审会议纪要   070
        supervisorFile.setType("070");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listhyjy_file = supervisorFileService.select(supervisorFile);
        //（5）监理审核报告   071
        supervisorFile.setType("071");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listshbg_file = supervisorFileService.select(supervisorFile);
        // 完成按钮状态
        getButFinishStatus(listjhjd_file, "067", request);
        //getButFinishStatus(ywfalist_file, "068", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据

        request.setAttribute("listhyjy_file", listhyjy_file);//（4） 专家评审意见和评审会议纪要
        request.setAttribute("listshbg_file", listshbg_file);//（5） 监理审核报告
        return "/supervisor/projectManager/ssjhfan";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 实施阶段----监理实施细则
     * @Date:9:33 2020/11/19
     */
    @Guide
    @GetMapping(value = "ssjlssxz")
    public String ssjlssxz(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        ProjectContract projectContract = new ProjectContract();
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listssxz_file = null;// 监理实施细则
        //(1) 066  监理实施细则
        supervisorFile.setType("066");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listssxz_file = supervisorFileService.select(supervisorFile);

        //完成按钮
        getButFinishStatus(listssxz_file, "066", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listssxz_file", listssxz_file);//（1） 计划进度
        return "/supervisor/projectManager/ssjlssxz";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:检查评审
     * @Date:10:47 2020/11/27
     */
    @Guide
    @GetMapping(value = "ss_jcps")
    public String ss_jcps(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        //(1) 107  文档审核报告
        supervisorFile.setType("107");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listwdbg_file = supervisorFileService.select(supervisorFile);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);
        request.setAttribute("listwdbg_file", listwdbg_file);//
        return "/supervisor/projectManager/ss_jcps";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 实施阶段-----检验评估
     * @Date:10:12 2020/11/10
     */
    @Guide
    @GetMapping(value = "jypg")
    public String jypg(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listzjbg_file = null;//  049 检验评估报告

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 049 检验评估报告
        supervisorFile.setType("049");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listzjbg_file = supervisorFileService.select(supervisorFile);

        // 检验评估报告
        getButFinishStatus(listzjbg_file, "049", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listzjbg_file", listzjbg_file);//  049 检验评估报告
        return "/supervisor/projectManager/jypg";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 培训
     * @Date:11:11 2020/11/10
     */
    @Guide
    @GetMapping(value = "px")
    public String px(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listzjbg_file = null;//   050  培训签到表
        List<SupervisorFile> listjyjc_file = null;//   051 培训资料


        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        //  050 培训签到表
        supervisorFile.setType("050");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listzjbg_file = supervisorFileService.select(supervisorFile);
        // 051  培训资料
        supervisorFile.setType("051");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjyjc_file = supervisorFileService.select(supervisorFile);


        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listzjbg_file", listzjbg_file);//  050 培训签到表
        request.setAttribute("listjyjc_file", listjyjc_file); //  051 培训资料
        return "/supervisor/projectManager/px";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 验收阶段  --------初验
     * @Date:12:00 2020/11/10
     */
    @Guide
    @GetMapping(value = "firstYs")
    public String firstYs(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listsqb_file = null;//   052 工程初验申请表
        List<SupervisorFile> listshbg_file = null;//   053 文档审核报告
        List<SupervisorFile> listzjbg_file = null;//   054  监理工作总结报告
        List<SupervisorFile> listjy_file = null;//   055  初验报告
        List<SupervisorFile> listhy_file = null;//   075  会议纪要


        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        //  052 工程初验申请表
        supervisorFile.setType("052");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listsqb_file = supervisorFileService.select(supervisorFile);
        // 053  文档审核报告
        supervisorFile.setType("053");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listshbg_file = supervisorFileService.select(supervisorFile);
        //  054  监理工作总结报告
        supervisorFile.setType("054");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listzjbg_file = supervisorFileService.select(supervisorFile);
        //  055 验收报告
        supervisorFile.setType("055");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjy_file = supervisorFileService.select(supervisorFile);
        //  075 会议纪要
        supervisorFile.setType("075");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listhy_file = supervisorFileService.select(supervisorFile);

        getButFinishStatus(listsqb_file, "052", request);
        getButFinishStatus(listzjbg_file, "054", request);
        getButFinishStatus(listjy_file, "055", request);
        getButFinishStatus(listhy_file, "075", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listsqb_file", listsqb_file);//       052 工程初验申请表
        request.setAttribute("listshbg_file", listshbg_file); //     053 文档审核报告
        request.setAttribute("listzjbg_file", listzjbg_file);//      054  监理工作总结报告
        request.setAttribute("listjy_file", listjy_file); //         055  初验报告
        request.setAttribute("listhy_file", listhy_file); //         075  会议纪要
        return "/supervisor/projectManager/firstYs";
    }

    /**
     * @param model   //  056  试运行记录  057   试运行报告  058  用户使用意见
     * @param request
     * @Author:zhaoyongke
     * @Description: 验收阶段 -----试运行
     * @Date:14:09 2020/11/10
     */
    @Guide
    @GetMapping(value = "syx")
    public String syx(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        return "/supervisor/projectManager/syx";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 验收阶段-------------------------》终验：059工程终验报审表 060    监理工作总结报告     061 终审报告和会议纪要
     * @Date:14:46 2020/11/10
     */
    @Guide
    @GetMapping(value = "endYs")
    public String endYs(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listys_file = null;//   059     工程终验报审表
        List<SupervisorFile> listzj_file = null;//   060     监理工作总结报告
        List<SupervisorFile> listjy_file = null;//  061      终审报告和会议纪要
        List<SupervisorFile> listhyjy_file = null;//  会议纪要

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        //  059 工程终验报审表
        supervisorFile.setType("059");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listys_file = supervisorFileService.select(supervisorFile);


        //060  监理工作总结报告
        supervisorFile.setType("060");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listzj_file = supervisorFileService.select(supervisorFile);
        //061  终审报告和会议纪要
        supervisorFile.setType("061");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjy_file = supervisorFileService.select(supervisorFile);

        supervisorFile.setType("076");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listhyjy_file = supervisorFileService.select(supervisorFile);

        //完成按钮状态
        getButFinishStatus(listys_file, "059", request);
        getButFinishStatus(listzj_file, "060", request);
        getButFinishStatus(listjy_file, "061", request);
        getButFinishStatus(listhyjy_file, "076", request);


        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listys_file", listys_file);//    059  工程终验报审表
        request.setAttribute("listzj_file", listzj_file); //   060   监理工作总结报告
        request.setAttribute("listjy_file", listjy_file); //   061   终审报告和会议纪要
        request.setAttribute("listhyjy_file", listhyjy_file);

        return "/supervisor/projectManager/endYs";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 移交  062  承建工程移交单   063  监理文档移交单
     * @Date:15:31 2020/11/10
     */
    @Guide
    @GetMapping(value = "transfer")
    public String transfer(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listcjyj_file = null;//   062     承建工程移交单
        List<SupervisorFile> listjlyj_file = null;//   063     监理文档移交单


        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        //   062  承建工程移交单
        supervisorFile.setType("062");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);


        //063  监理文档移交单
        supervisorFile.setType("063");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjlyj_file = supervisorFileService.select(supervisorFile);

        getButFinishStatus(listcjyj_file, "062", request);
        getButFinishStatus(listjlyj_file, "063", request);


        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);//    062  承建工程移交单
        request.setAttribute("listjlyj_file", listjlyj_file);//    063  监理文档移交单
        return "/supervisor/projectManager/transfer";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 工程款支付
     * @Date:11:19 2020/11/27
     */
    @Guide
    @GetMapping(value = "ys_gckzf")
    public String ys_gckzf(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        // 查询付款次数
        SupervisorProjectPay supervisorProjectPay = new SupervisorProjectPay();
        supervisorProjectPay.setSppPrjid(id);
        List<SupervisorProjectPay> listpay = supervisorProjectPayService.select(supervisorProjectPay);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listcj_file = null;//   108
        List<SupervisorFile> listwdbg_file = null;//   109
        List<SupervisorFile> listwdzf_file = null;//   110

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        //承建付款申请
        Example ecj = new Example(SupervisorFile.class);
        Example.Criteria ccj = ecj.createCriteria();
        ccj.andEqualTo("projectId", id).andEqualTo("spmId", spmid).andEqualTo("type", "108").andIsNull("parentId");
        listcj_file = supervisorFileService.selectByExample(ecj);

        Example e = new Example(SupervisorFile.class);
        Example.Criteria c = e.createCriteria();
        c.andEqualTo("projectId", id).andEqualTo("spmId", spmid).andEqualTo("type", "109").andIsNull("parentId");
        listwdbg_file = supervisorFileService.selectByExample(e);

        //110
        supervisorFile.setType("110");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listwdzf_file = supervisorFileService.select(supervisorFile);
        /*完成按钮状态*/
        /*  getButFinishStatus(listcj_file, "108", request);*/
        getButFinishStatus(listwdbg_file, "109", request);
        getButFinishStatus(listwdzf_file, "110", request);


        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listpay", listpay);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listwdbg_file", listwdbg_file);//
        request.setAttribute("listwdzf_file", listwdzf_file);//
        return "/supervisor/projectManager/ys_gckzf";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:验收阶段---验收
     * @Date:13:20 2020/11/19
     */
    @Guide
    @GetMapping(value = "ys")
    public String ys(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listfwysbs_file = null;//    077     服务验收报审表
        List<SupervisorFile> listcjyj_file = null;//    079     文档审核报告
        List<SupervisorFile> listjlyj_file = null;//    080     监理工作总结
        List<SupervisorFile> listys_file = null;//     081     验收报告
        List<SupervisorFile> listhy_file = null;//     082     会议纪要

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        /*服务验收报审表*/
        supervisorFile.setType("077");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listfwysbs_file = supervisorFileService.select(supervisorFile);

        supervisorFile.setType("079");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);
        supervisorFile.setType("080");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjlyj_file = supervisorFileService.select(supervisorFile);
        supervisorFile.setType("081");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listys_file = supervisorFileService.select(supervisorFile);
        supervisorFile.setType("082");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listhy_file = supervisorFileService.select(supervisorFile);

        /*完成按钮状态*/
        //服务验收报审表
        getButFinishStatus(listfwysbs_file, "077", request);
        //监理工作总结
        getButFinishStatus(listjlyj_file, "080", request);
        //验收报告
        getButFinishStatus(listys_file, "081", request);
        //会议纪要
        getButFinishStatus(listhy_file, "082", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);//    079  文档审核报告
        request.setAttribute("listjlyj_file", listjlyj_file);//    080  监理工作总结
        request.setAttribute("listys_file", listys_file);//    081  验收报告
        request.setAttribute("listhy_file", listhy_file);//    082  会议纪要
        return "/supervisor/projectManager/ys";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:验收阶段-----运行维护服务评估报告 083   运行维护服务评估报告 文件
     * @Date:14:35 2020/11/19
     */
    @Guide
    @GetMapping(value = "yxwhbg")
    public String yxwhbg(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listcjyj_file = null;//    083    运行维护服务评估报告

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        supervisorFile.setType("083");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);
        /*完成按钮状态*/
        getButFinishStatus(listcjyj_file, "083", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);//    083  运行维护服务评估报告
        return "/supervisor/projectManager/yxwhbg";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作----项目会议
     * @Date:15:46 2020/11/19
     */
    @Guide
    @GetMapping(value = "qt_xmhy")
    public String qt_xmhy(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listcjyj_file = null;//    084    会议纪要
        List<SupervisorFile> listcjqd_file = null;//    085    签到表

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        // 会议纪要
        supervisorFile.setType("084");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);

        // 签到表
        supervisorFile.setType("085");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjqd_file = supervisorFileService.select(supervisorFile);

        /*完成按钮状态*/
        getButFinishStatus(listcjyj_file, "084", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);
        request.setAttribute("listcjqd_file", listcjqd_file);
        return "/supervisor/projectManager/qt_xmhy";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 其他监理工作----监理周报
     * @Date:17:49 2020/11/19
     */
    @Guide
    @GetMapping(value = "qt_jlzb")
    public String qt_jlzb(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listzb_file = null;  // 监理周报

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 监理周报
        supervisorFile.setType("086");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listzb_file = supervisorFileService.select(supervisorFile);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listzb_file", listzb_file);

        return "/supervisor/projectManager/qt_jlzb";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他：工程款 支付
     * @Date:13:19 2020/11/27
     */
    @Guide
    @GetMapping(value = "qt_gcpay")
    public String qt_gcpay(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        SupervisorProjectPay supervisorProjectPay = new SupervisorProjectPay();
        supervisorProjectPay.setSppPrjid(id);
        List<SupervisorProjectPay> listpay = supervisorProjectPayService.select(supervisorProjectPay);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listcj_file = null;//    088    监理付款申请
        List<SupervisorFile> listwdbg_file = null;//    088    监理付款申请
        List<SupervisorFile> listwdzf_file = null;//    089    支付意见

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        //承建付款申请
        Example ecj = new Example(SupervisorFile.class);
        Example.Criteria ccj = ecj.createCriteria();
        ccj.andEqualTo("projectId", id).andEqualTo("spmId", spmid).andEqualTo("type", "087").andIsNull("parentId");
        listcj_file = supervisorFileService.selectByExample(ecj);

        // 监理付款申请
        Example e = new Example(SupervisorFile.class);
        Example.Criteria c = e.createCriteria();
        c.andEqualTo("projectId", id).andEqualTo("spmId", spmid).andEqualTo("type", "088").andIsNull("parentId");
        listwdbg_file = supervisorFileService.selectByExample(e);

        // 支付意见
        supervisorFile.setType("089");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listwdzf_file = supervisorFileService.select(supervisorFile);

        /*完成按钮状态*/
        /*     getButFinishStatus(listcj_file, "087", request);*/
        getButFinishStatus(listwdbg_file, "088", request);
        getButFinishStatus(listwdzf_file, "089", request);


        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listwdbg_file", listwdbg_file);//
        request.setAttribute("listwdzf_file", listwdzf_file);//
        request.setAttribute("listpay", listpay);
        return "/supervisor/projectManager/qt_gcpay";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 其他监理工作----监理工作联系单
     * @Date:9:09 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_gzlxd")
    public String qt_gzlxd(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listcjyj_file = null;//    090    监理工作联系单

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        // 监理工作联系单
        supervisorFile.setType("090");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);
        /*完成按钮状态*/
        getButFinishStatus(listcjyj_file, "090", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);
        return "/supervisor/projectManager/qt_gzlxd";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作-----监理通知
     * @Date:9:14 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_jltz")
    public String qt_jltz(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listcjyj_file = null;//

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        // 监理通知
        supervisorFile.setType("091");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);
        /*承建单位只能查看到项目经理选择的承建单位*/
        Boolean iscj = projectUnitConstructionService.isCjUser(id);
        if (iscj) {
            for (int i = 0; i < listcjyj_file.size(); i++) {
                String formId = listcjyj_file.get(i).getLinkId();
                if (StringUtil.isNotBlank(formId) && !formId.equals(null)) {
                    SupervisorProjectForms from = supervisorProjectFormsService.selectByPrimaryKey(formId);
                    /*该字段存放的是承建项目经理userid*/
                    String cjManageUserId = from.getSpfF30() + "";
                    String currUserId = CommonUtil.getUserId();
                    if (!currUserId.equals(cjManageUserId)) {
                        listcjyj_file.remove(i);
                    }
                }
            }

        }

        /*完成按钮状态*/
        getButFinishStatus(listcjyj_file, "091", request);
        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);
        return "/supervisor/projectManager/qt_jltz";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作-----专项报告
     * @Date:9:16 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_zxbg")
    public String qt_zxbg(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();

        List<SupervisorFile> listcjyj_file = null;//    090    监理工作联系单
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 专项报告
        supervisorFile.setType("092");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);

        /*完成按钮状态*/
        getButFinishStatus(listcjyj_file, "092", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);
        return "/supervisor/projectManager/qt_zxbg";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作----变更处理
     * @Date:9:21 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_bgcl")
    public String qt_bgcl(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listgcbg_file = null;//
        List<SupervisorFile> listbg_file = null;//
        List<SupervisorFile> listtj_file = null;//
        List<SupervisorFile> listqz_file = null;//
        List<SupervisorFile> listqt_file = null;//


        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 工程变更单
        supervisorFile.setType("093");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listgcbg_file = supervisorFileService.select(supervisorFile);
        // 变更审核报告
        supervisorFile.setType("094");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listbg_file = supervisorFileService.select(supervisorFile);

        // 变更统计表
        supervisorFile.setType("095");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listtj_file = supervisorFileService.select(supervisorFile);


        // 工程变更单其他
        supervisorFile.setType("118");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listqt_file = supervisorFileService.select(supervisorFile);

        // 签证单
        supervisorFile.setType("096");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listqz_file = supervisorFileService.select(supervisorFile);

        /*完成按钮状态*/
        getButFinishStatus(listgcbg_file, "093", request);
        getButFinishStatus(listbg_file, "094", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listbg_file", listbg_file);
        request.setAttribute("listtj_file", listtj_file);
        request.setAttribute("listqz_file", listqz_file);
        request.setAttribute("listqt_file", listqt_file);

        return "/supervisor/projectManager/qt_bgcl";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作----延期处理 097 工程延期申请表
     * @Date:9:25 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_yqcl")
    public String qt_yqcl(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listcjyj_file = null;//    090    监理工作联系单
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 延期处理
        supervisorFile.setType("097");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);

        /*完成按钮状态*/
        getButFinishStatus(listcjyj_file, "097", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);
        return "/supervisor/projectManager/qt_yqcl";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作-----工程备忘
     * @Date:10:54 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_gcbw")
    public String qt_gcbw(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();

        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listcjyj_file = null;//
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 工程备忘表
        supervisorFile.setType("098");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listcjyj_file = supervisorFileService.select(supervisorFile);

        /*完成按钮状态*/
        getButFinishStatus(listcjyj_file, "098", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listcjyj_file", listcjyj_file);
        return "/supervisor/projectManager/qt_gcbw";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作----业务联系单 099 业务联系单 分包展示
     * @Date:10:59 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_ywlxd")
    public String qt_ywlxd(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setType("099");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        List<SupervisorFile> listywlxd_file = supervisorFileService.select(supervisorFile);

        /*完成按钮状态*/
        getButFinishStatus(listywlxd_file, "099", request);

        //-------------------
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        return "/supervisor/projectManager/qt_ywlxd";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作 ----其他文件
     * @Date:11:48 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_otherwj")
    public String qt_otherwj(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listjlrz_file = null;//监理日志
        List<SupervisorFile> listjlyb_file = null;//监理月报
        List<SupervisorFile> listother_file = null;//其他文档
        List<SupervisorFile> listtzzm_file = null;//投资证明
        List<SupervisorFile> listbyx_file = null;//表扬信

        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        // 监理日志 100
        supervisorFile.setType("100");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjlrz_file = supervisorFileService.select(supervisorFile);
        //监理月报  101
        supervisorFile.setType("101");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjlyb_file = supervisorFileService.select(supervisorFile);
        //其他文档  102
        supervisorFile.setType("102");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listother_file = supervisorFileService.select(supervisorFile);

        // 2021 0820 添加 投资证明 121  和 表扬信 122
        supervisorFile.setType("121");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listtzzm_file = supervisorFileService.select(supervisorFile);

        // 表扬信
        supervisorFile.setType("122");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listbyx_file = supervisorFileService.select(supervisorFile);







        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listjlrz_file", listjlrz_file);// 监理日志
        request.setAttribute("listjlyb_file", listjlyb_file);// 监理月报
        request.setAttribute("listother_file", listother_file);// 其他文档
        request.setAttribute("listtzzm_file", listtzzm_file);// 投资证明
        request.setAttribute("listbyx_file", listbyx_file);// 表扬信

        return "/supervisor/projectManager/qt_otherwj";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 其他监理工作-----案例总结
     * @Date:14:06 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_alzj")
    public String qt_alzj(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listjlrz_file = null;//项目案例总结
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        // 项目案例总结
        supervisorFile.setType("103");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjlrz_file = supervisorFileService.select(supervisorFile);

        getButFinishStatus(listjlrz_file, "103", request);
        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listjlrz_file", listjlrz_file);// 项目案例总结

        return "/supervisor/projectManager/qt_alzj";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 其他监理工作 -----行业总结
     * @Date:14:17 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_hyzj")
    public String qt_hyzj(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listjlrz_file = null;//行业总结
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");

        // 行业总结
        supervisorFile.setType("104");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjlrz_file = supervisorFileService.select(supervisorFile);
        getButFinishStatus(listjlrz_file, "104", request);
        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listjlrz_file", listjlrz_file);// 行业总结

        return "/supervisor/projectManager/qt_hyzj";
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作------束后总结
     * @Date:14:25 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_shzj")
    public String qt_shzj(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listjlrz_file = null;//行业总结
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 束后总结
        supervisorFile.setType("105");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjlrz_file = supervisorFileService.select(supervisorFile);

        getButFinishStatus(listjlrz_file, "105", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listjlrz_file", listjlrz_file);// 束后总结

        return "/supervisor/projectManager/qt_shzj";
    }


    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description:其他监理工作------知识点
     * @Date:14:25 2020/11/20
     */
    @Guide
    @GetMapping(value = "qt_zsd")
    public String qt_zsd(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        SupervisorProject supervisorProject = new SupervisorProject();
        //查询项目
        supervisorProject.setId(id);
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        //查询里程
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spmid);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        // 查询阶段
        SupervisorProjectStage stage = new SupervisorProjectStage();
        stage.setId(stageid);
        stage = supervisorProjectStageService.selectByPrimaryKey(stage);
        //-------------------
        SupervisorFile supervisorFile = new SupervisorFile();
        List<SupervisorFile> listjlrz_file = null;//行业总结
        // 查询分包表
        List<ProjectContract> listsqs_fb = getProjectContracts(id, "001");
        // 知识点
        supervisorFile.setType("114");
        supervisorFile.setProjectId(id);
        supervisorFile.setSpmId(spmid);
        listjlrz_file = supervisorFileService.select(supervisorFile);


        getButFinishStatus(listjlrz_file, "114", request);

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);//项目
        request.setAttribute("lcdto", milepost);// 里程
        request.setAttribute("stagedto", stage);
        request.setAttribute("listsqs_fb", listsqs_fb);// 分包数据
        request.setAttribute("listjlrz_file", listjlrz_file);// 知识点

        return "/supervisor/projectManager/qt_zsd";
    }


    /**
     * @param request
     * @Author:zhaoyongke
     * @Description: 查询分包的文件  该方法 不针对 文件下的图片查询
     * @Date:8:52 2020/11/6
     */
    @GetMapping(value = "getFbList")
    @ResponseBody
    public JsonUtil getFbList(HttpServletRequest request) {
        JsonUtil reJs = new JsonUtil();
        try {
            String project_id = request.getParameter("projectId");
            String spmId = request.getParameter("spmId");
            String fbId = request.getParameter("fbId");
            String type = request.getParameter("type");

            Example e = new Example(SupervisorFile.class);
            Example.Criteria c = e.createCriteria();
            c.andEqualTo("projectId", project_id).andEqualTo("spmId", spmId).andEqualTo("pcId", fbId).andEqualTo("type", type).andIsNull("parentId");
            List<SupervisorFile> listfb = supervisorFileService.selectByExample(e);
            reJs.setMsg("获取成功。");
            reJs.setFlag(true);
            reJs.setData(listfb);
            return reJs;
        } catch (Exception e) {
            e.printStackTrace();
            reJs.setMsg("获取失败！！" + e.getMessage());
            reJs.setFlag(false);
            return reJs;
        }
    }

    /**
     * 下载文件权限控制
     */
    @GetMapping(value = "rightControl")
    @ResponseBody
    public JsonUtil rightControl(HttpServletRequest request) {
        JsonUtil re = new JsonUtil();
        String id = request.getParameter("id");// 文件id
        if (!StringUtil.isBlank(id)) {
            SupervisorFile supervisorFile = new SupervisorFile();
            supervisorFile.setId(id);
            supervisorFile = supervisorFileService.selectByPrimaryKey(supervisorFile);
            String role = sysUserService.getUserRole(supervisorFile.getProjectId());
            if ("cj".equals(role)) {
                BaseDict wjdict = DictUtil.getDictByCode(DictTypes.WJ, supervisorFile.getType());
                String level14 = wjdict.getBadtLevel14();
                if (!StringUtil.isBlank(level14)) {
                    if (level14.indexOf(role) < 0) {
                        re.setMsg("您没有权限导出文档");
                        re.setFlag(false);
                        return re;
                    }
                } else {
                    re.setMsg("您没有权限导出文档");
                    re.setFlag(false);
                    return re;
                }
            }
        }
        re.setMsg("导出成功");
        re.setFlag(true);
        return re;
    }

    /*
     * 下载文件
     * */
    @GetMapping(value = "exportFile")
    public void exportFile(HttpServletRequest request, HttpServletResponse response) {
        String id = request.getParameter("id");// 文件id
        String url = "";
        Integer downloadCount = 0;
        String fname="";
        if (!StringUtil.isBlank(id)) {
            SupervisorFile supervisorFile = new SupervisorFile();
            supervisorFile.setId(id);
            supervisorFile = supervisorFileService.selectByPrimaryKey(supervisorFile);
            downloadCount = supervisorFile.getDownloads();
            url = supervisorFile.getUrl();
            fname=supervisorFile.getFileName();
        } else {
            String filename = request.getParameter("filename");// 文件名称
            url = uploadPath + filename;
            fname=filename;
        }
        //修改下载量:
        SupervisorFile newDownloadFile = new SupervisorFile();
        newDownloadFile.setId(id);
        newDownloadFile.setDownloads(downloadCount == null ? 1 : ++downloadCount);
        supervisorFileService.updateByPrimaryKeySelective(newDownloadFile);
        String text="下载文件";
        String  param="参数：文件名称：" + fname;
        insertFileLog(text,param);
        // 保存日志
        ExportFileUtil.exportFile(response, request, url);
    }


    //日志
    public void insertFileLog(String text,String param ) {

        SysLog sysLog = new SysLog();
        sysLog.setCreateTime(new Date());
        sysLog.setType("ADD");
        sysLog.setText(text);
        sysLog.setParam(param);
        sysLog.setCreateTime(DateUtil.parseDate(DateUtil.getCurrentDateString()));
        CurrentUser currentUser = Principal.getCurrentUse();
        sysLog.setUserName(currentUser.getUsername());
        sysLogMapper.insert(sysLog);
    }

    /**
     * @param
     * @Author:zhaoyongke
     * @Description: 点击完成按钮 擦作
     * @Date:9:57 2020/11/7
     */
    @RequestMapping(value = "/updateFinish", method = RequestMethod.POST)
    @ResponseBody
    public JsonUtil updateFinish(HttpServletRequest request) {
        JsonUtil re = new JsonUtil();
        try {
            JSONObject jsonObject = new JSONObject();
            //项目id:
            String projectId = request.getParameter("id");
            // 完成类型 002 代表到货验收需要每个分包完成的情况
            String finshType = request.getParameter("finshType");
            // 完成第几步
            String fs_status = request.getParameter("fs_status");
            // 里程id
            String spm_Id = request.getParameter("spmId");
            // 阶段id
            String stageId = request.getParameter("stageId");
            String fileType = request.getParameter("fileType");
            //普通形式获取上传文件类型
            String fileTypePt = request.getParameter("fileTypePt");
            SupervisorProjectStage stagef = supervisorProjectStageService.selectByPrimaryKey(stageId);
            // 文件类型数量
            Integer typeNum = 0;
            if (request.getParameter("typeNum") != null) {
                typeNum = Integer.valueOf(request.getParameter("typeNum"));
            }
            //验证分包文件
            SupervisorProjectDTO checkPackageFile = new SupervisorProjectDTO();
            if (StringUtils.isNotBlank(fileType)) {
                //验证该文件类型是否是必选的:
                checkPackageFile.setType(fileType);
                boolean necessary = projectContractService.checkFileNecessary(checkPackageFile);
                if (necessary) {
                    checkPackageFile.setProjectId(projectId);
                    checkPackageFile.setSpmId(spm_Id);
                }
            }
            if ("002".equals(finshType)) {
                /*到货验收状态处理*/
                String restr = updateFinishDhys(re, jsonObject, fs_status, typeNum, projectId, stageId, spm_Id, stagef, checkPackageFile, request);
                if (StringUtil.isNotBlank(restr)) {
                    return JsonUtil.error(restr);
                }
            } else {
                /*非到货验收状态处理*/
                String restr = updateFinishSt(re, fileTypePt, fileType, jsonObject, fs_status, typeNum, projectId, stageId, spm_Id, stagef, checkPackageFile, request);
                if (StringUtil.isNotBlank(restr)) {
                    return JsonUtil.error(restr);
                }
            }
            updateAfFinish(projectId, stageId, jsonObject);
            if (jsonObject.get("fb_status") == null) {
                jsonObject.put("fb_status", "");
            }
            if (jsonObject.get("lc_status") == null) {
                jsonObject.put("lc_status", "");
            }
            if (jsonObject.get("jd_status") == null) {
                jsonObject.put("jd_status", "");
            }
            re.setData(jsonObject);
            re.setMsg("操作成功");
            re.setFlag(true);
        } catch (
                Exception e) {
            re.setMsg("操作失败！！" + e.getMessage());
            re.setFlag(false);
            e.printStackTrace();
        }
        return re;
    }

    /**
     * @param projectId
     * @param stageId
     * @param object
     * @Author:zhaoyongke
     * @Description:延期的阶段和项目 恢复原来状态
     * @Date:18:41 2021/3/5
     */
    public void updateAfFinish(String projectId, String stageId, JSONObject object) {
        SupervisorProjectStage stage = supervisorProjectStageService.selectByPrimaryKey(stageId);
        String stageStatus = stage.getFinishStatus();
        if ("3".equals(stageStatus)) {
            SupervisorProjectMilepost milepostYc = new SupervisorProjectMilepost();
            milepostYc.setProjectId(projectId);
            milepostYc.setSupervisorProjectStageId(stageId);
            milepostYc.setFinishStatus("3");
            int countlc = supervisorProjectMilepostService.selectCount(milepostYc);
            if (countlc == 0) {
                // 没有延期的里程 修改回原状态(不会是 0 2 )
                stage.setFinishStatus("1");
                object.put("jd_status", "1");
                supervisorProjectStageService.updateByPrimaryKey(stage);
            }
        }


        SupervisorProject projectselect = supervisorProjectService.selectByPrimaryKey(projectId);
        String status = projectselect.getStatus();
        if ("005".equals(status)) {
            // 如果是延期
            SupervisorProjectMilepost milepostYc = new SupervisorProjectMilepost();
            milepostYc.setProjectId(projectId);
            milepostYc.setFinishStatus("3");
            int countjd = supervisorProjectMilepostService.selectCount(milepostYc);
            if (countjd == 0) {
                //修改回原状态
                if (projectselect.getFinishDate() != null) {
                    //003 已完成
                    projectselect.setStatus("003");
                } else if (projectselect.getStartTime() != null) {
                    //004 进行中
                    projectselect.setStatus("004");
                } else if (projectselect.getCommitDate() != null) {
                    //002 未启动
                    projectselect.setStatus("002");
                } else {
                    //001 未提交
                    projectselect.setStatus("001");
                }
                supervisorProjectService.updateByPrimaryKey(projectselect);
            }


        }


    }

    /**
     * @param re
     * @param fileTypePt
     * @param fileType
     * @param jsonObject
     * @param fs_status
     * @param typeNum
     * @param projectId
     * @param stageId
     * @param spm_Id
     * @param stagef
     * @param checkPackageFile
     * @param request
     * @Author:zhaoyongke
     * @Description:完成状态的处理
     * @Date:16:11 2021/1/24
     */
    public String updateFinishSt(JsonUtil re, String fileTypePt, String fileType, JSONObject jsonObject, String fs_status, Integer typeNum, String projectId, String stageId, String spm_Id, SupervisorProjectStage stagef, SupervisorProjectDTO checkPackageFile, HttpServletRequest request) throws Exception {
        String restr = "";
        if (StringUtils.isNotBlank(checkPackageFile.getProjectId())) {
            boolean atLeastOne = projectContractService.checkFileAtLeastOne(checkPackageFile);
            /*if (!atLeastOne) {
                restr = "请上传文件";
                return restr;
            }*/
        }
        /*验证文件类型 必须包含一个文件*/
        if (StringUtil.isNotBlank(fileTypePt)) {
            SupervisorProjectDTO supervisorPro = new SupervisorProjectDTO();
            supervisorPro.setType(fileTypePt);
            boolean necessary = projectContractService.checkFileNecessary(supervisorPro);
            if (necessary) {
                /*需要校验文件*/
                SupervisorFile checkFile = new SupervisorFile();
                checkFile.setType(fileTypePt);
                checkFile.setProjectId(projectId);
                checkFile.setSpmId(spm_Id);
                int countfile = supervisorFileService.selectCount(checkFile);
                /*if (countfile == 0) {
                    restr = "请上传文件后，再完成";
                    return restr;
                }*/
            }
        }
        // 查询；里程表
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spm_Id);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);
        String mepostNo = milepost.getMilepostNo();// 里程编号
        String step_num = milepost.getStepNum();
        // 数据库取出的完成状态
        String finishstatus = milepost.getFinishStatus();
        Integer num = 0;
        String[] ayStatus = step_num.split(",");
        String asPostStartIdx = fs_status.substring(0, 1);// 例如  10  20  截取  为  1 , 2
        //不是完成状态 则修改为完成状态
        if (!ayStatus[Integer.valueOf(asPostStartIdx) - 1].substring(1, 2).equals("2")) {
            ayStatus[Integer.valueOf(asPostStartIdx) - 1] = fs_status;// 数组更新状态
            String str = Arrays.toString(ayStatus).replace("[", "").replace("]", "").replace(" ", "");
            milepost.setStepNum(str);
            // 更新状态字符串
            supervisorProjectMilepostService.updateByPrimaryKey(milepost);
        }
        if ("004".equals(mepostNo)) {
            //开工准备项目章授权书（可选）
            ayStatus[2] = "32";
        } else if ("006".equals(mepostNo)) {
            /*设计和方案*/
            //实施方案专家评审意见（可选）
            //评审会议纪要（可选）
            ayStatus[3] = "42";
            ayStatus[4] = "52";
        } else if ("015".equals(mepostNo)) {
            /*里程编号-- 计划方案中 运维方案专家评审意见（可选） 评审会议纪要（可选）  */
            ayStatus[2] = "32";
            ayStatus[3] = "42";
        } else if ("033".equals(mepostNo)) {
            /*变更处理 033 签证单（可选）*/
            ayStatus[3] = "42";
        } else if ("009".equals(mepostNo)) {
            /*设计文件*/
            //设计专家评审意见（可选）
            //评审会议纪要（可选）
            ayStatus[1] = "22";
            ayStatus[2] = "32";
        } else if ("008".equals(mepostNo)) {
            /*需求文件*/
            //需求专家评审意见（可选）
            //评审会议纪要（可选）
            ayStatus[2] = "32";
            ayStatus[3] = "42";
        } else if ("010".equals(mepostNo)) {
            /*深化设计文件*/
            //深化设计专家评审意见（可选）
            //评审会议纪要（可选）
            ayStatus[1] = "22";
            ayStatus[2] = "32";
        }
        for (int i = 0; i < ayStatus.length; i++) {// 判断是否都完成以2结尾的数量统计
            if (ayStatus[i].trim().substring(1, 2).equals("2")) {
                num++;
            }
        }
        // （1）本文件状态完成
        jsonObject.put("wj_status", "2");
        // （2）下面处理里程的状态
        if (!"2".equals(finishstatus)) { // 如果前台传入的文件类型和遍历计算的数量一致 则修改里程为已经完成
            if (typeNum == num) {
                /*判断里程是否延期*/
                /*里程完成*/
                milepost.setFinishStatus("2");
                milepost.setFinishDate(DateUtil.getCurrentDateString());
                supervisorProjectMilepostService.updateByPrimaryKey(milepost);
                /*监理通知文档合并*/
                try {
                    updatedohbwd(milepost);
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new Exception("合并文档出错");
                }
                // 该里程完成
                jsonObject.put("lc_status", "2");
                //如果该里程是首次会议，那么更改项目状态为进行中
                supervisorProjectService.updateProjectStatusAfterMilepostFinish(milepost);
            } else {
                // 如果状态是0 侧修改成进行中
                if ("0".equals(milepost.getFinishStatus())) {
                    milepost.setFinishStatus("1");
                    supervisorProjectMilepostService.updateByPrimaryKey(milepost);
                    // 该里程为进行中
                    jsonObject.put("lc_status", "1");
                }
            }
        } else {
            // 如果是已经完成 则不用修改状态

        }
        // （3）下面处理 阶段的状态  该阶段下所有的里程都完成后 ，该阶段完成
        // 获得阶段
        Example example = new Example(SupervisorProjectMilepost.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("supervisorProjectStageId", stageId);
        criteria.andIsNull("finishDate");
         /*       criteria.andNotEqualTo("finishStatus", "2");//  2 是 已完成
                criteria.andNotEqualTo("finishStatus", "3");//  3 是 延迟*/
        // example.setOrderByClause("status  desc ");
        Integer count = supervisorProjectMilepostService.selectCountByExample(example);

        /*阶段编号*/
        String stageNo = stagef.getStageNo();
        Boolean qtIsfinsih = false;
        //注意：其他监理工作阶段  项目会议和监理周报 这两个里程碑完成后，整个阶段就设置完成状态
        if ("005".equals(stageNo)) {
            // 查询项目会议和监理周报 是否完成
            Example exampleLc = new Example(SupervisorProjectMilepost.class);
            Example.Criteria criteriaLc = exampleLc.createCriteria();
            Example.Criteria criteria2 = exampleLc.and();
            criteriaLc.andEqualTo("supervisorProjectStageId", stageId);
            criteria.andIsNull("finishDate");
            // criteriaLc.andNotEqualTo("finishStatus", "2");//   2 是 已完成
            criteria2.orEqualTo("milepostNo", "027");//项目会议
            criteria2.orEqualTo("milepostNo", "028");//监理周报
            int countqt = supervisorProjectMilepostService.selectCountByExample(exampleLc);
            if (countqt == 0) {
                qtIsfinsih = true;
            }
        }
        // 所有的都是已经完成
        if (count == 0 || qtIsfinsih) {
            // 更新
            /*阶段完成*/
            String jdstatus = updategetjdStatus(stagef);
            stagef.setFinishStatus(jdstatus);
            stagef.setFinishDate(DateUtil.getCurrentDateString());
            jsonObject.put("jd_status", jdstatus);
            supervisorProjectStageService.updateByPrimaryKey(stagef);
            //如果该阶段是验收阶段，那么设置项目状态为结束
            supervisorProjectService.updateProjectStatusAfterStageFinish(stagef);
            if (!"005".equals(stagef.getStageNo())) {
                String  logtext="aaaaaaa";
                BigDecimal bigDecimal = supervisorProjectService.calProgress(stagef,logtext);
                jsonObject.put("progress", bigDecimal);
            }
        } else {
            String jd_status = stagef.getFinishStatus(); // 阶段完成状态
            if (jd_status.equals("0")) {
                // 未进行修改为进行中
                stagef.setFinishStatus("1");
                jsonObject.put("jd_status", "1");
                supervisorProjectStageService.updateByPrimaryKey(stagef);
            }
            if (StringUtils.isNotBlank(milepost.getFinishDate())
                    && ("2".equals(milepost.getFinishStatus()) || "3".equals(milepost.getFinishStatus()))
                    && !"005".equals(stagef.getStageNo())) {
                String  logtext="bbbbbbbbbbbbb";
                BigDecimal bigDecimal = supervisorProjectService.calProgress(milepost,logtext);
                jsonObject.put("progress", bigDecimal);
            }
        }
        return restr;
    }

    /**
     * @param re
     * @param jsonObject
     * @param fs_status
     * @param typeNum
     * @param projectId
     * @param stageId
     * @param spm_Id
     * @param stagef
     * @param checkPackageFile
     * @param request
     * @Author:zhaoyongke
     * @Description: 到货验收处理
     * @Date:16:03 2021/1/24
     */
    public String updateFinishDhys(JsonUtil re, JSONObject jsonObject, String fs_status, Integer typeNum, String projectId, String stageId, String spm_Id, SupervisorProjectStage stagef, SupervisorProjectDTO checkPackageFile, HttpServletRequest request) throws Exception {

        String restr = "";
        // 针对到货验收处理
        // 分包id
        String fbId = request.getParameter("fbId");
        if (StringUtils.isNotBlank(checkPackageFile.getProjectId()) && StringUtils.isNotBlank(fbId)) {
            checkPackageFile.setFbId(fbId);
            boolean atLeastOne = projectContractService.checkFileAtLeastOne(checkPackageFile);
            if (!atLeastOne) {
//                restr = "有未完成的分包";
//                return restr;
            }
        }
        // 查询；里程表
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setId(spm_Id);
        milepost = supervisorProjectMilepostService.selectByPrimaryKey(milepost);

        ProjectContract contract = new ProjectContract();
        contract.setId(fbId);
        contract = projectContractService.selectByPrimaryKey(contract);
        // 查询分包表
        String step_num = contract.getStepNum();
        // 数据库取出的完成状态
        String finishstatus = contract.getFinishStatus();
        Integer num = 0;
        String[] ayStatus = step_num.split(",");
        String asPostStartIdx = fs_status.substring(0, 1);// 例如  10  20  截取  为  1 , 2
        if (!ayStatus[Integer.valueOf(asPostStartIdx) - 1].substring(1, 2).equals("2")) {
            ayStatus[Integer.valueOf(asPostStartIdx) - 1] = fs_status;// 数组更新状态
            String str = Arrays.toString(ayStatus).replace("[", "").replace("]", "").replace(" ", "");
            contract.setStepNum(str);
            // 更新状态字符串
            projectContractService.updateByPrimaryKey(contract);
        }
        //序列号 验证记录 为非必填
        ayStatus[2] = "32";
        for (int i = 0; i < ayStatus.length; i++) {// 判断是否都完成以2结尾的数量统计
            if (ayStatus[i].trim().substring(1, 2).equals("2")) {
                num++;
            }
        }
        //（1）本文件 状态 已完成
        jsonObject.put("wj_status", "1");
        // （2）下面处理分包状态
        if (!"2".equals(finishstatus)) {
            if (typeNum == num) {
                contract.setFinishStatus("2");
                projectContractService.updateByPrimaryKey(contract);
                // 该分包完成
                jsonObject.put("fb_status", "2");
            } else {
                // 如果状态是0 侧修改成进行中
                if ("0".equals(contract.getFinishStatus())) {
                    contract.setFinishStatus("1");
                    projectContractService.updateByPrimaryKey(contract);
                    // 该里程为进行中
                    jsonObject.put("fb_status", "1");
                }
            }

        } else {
            // 如果是已经完成 则不用修改状态

        }
        // （3）下面处理 里程的状态  判断每个分包的状态是否都是已完成  查询整个项目的分包
        Example example = new Example(ProjectContract.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("projectId", projectId);
        criteria.andNotEqualTo("finishStatus", "2");//  2 是 已完成
        ProjectUnitConstruction projectUnitConstruction = new ProjectUnitConstruction();
        projectUnitConstruction.setSupervisorProjectId(projectId);
        //是否有到货验收
        projectUnitConstruction.setInspectionMerchandise("1");
        List<ProjectUnitConstruction> select = projectUnitConstructionService.select(projectUnitConstruction);
        List<String> listti = new ArrayList<>();
        for (int i = 0; i < select.size(); i++) {
            String fbcode = select.get(i).getConstructionSubContractNumber();
            listti.add(fbcode);
        }
        criteria.andIn("code", listti);
        Integer count = projectContractService.selectCountByExample(example);
        if (count == 0) {
            // 更新里程
            /*里程完成*/
            milepost.setFinishStatus("2");
            milepost.setFinishDate(DateUtil.getCurrentDateString());
            jsonObject.put("lc_status", "2");
            supervisorProjectMilepostService.updateByPrimaryKey(milepost);
            //如果该里程是首次会议，那么更改项目状态为进行中
            supervisorProjectService.updateProjectStatusAfterMilepostFinish(milepost);
        } else {
            String jd_status = milepost.getFinishStatus(); // 阶段完成状态
            if (jd_status.equals("0")) {
                // 未进行修改为进行中
                milepost.setFinishStatus("1");
                jsonObject.put("lc_status", "1");
                supervisorProjectMilepostService.updateByPrimaryKey(milepost);
            }
        }
        // （3）下面处理 阶段的状态  判断每个里程的状态
        SupervisorProjectStage stage = new SupervisorProjectStage();
        // 获得阶段
        Example exampleMile = new Example(SupervisorProjectMilepost.class);
        Example.Criteria criteriaMile = exampleMile.createCriteria();
        criteriaMile.andEqualTo("supervisorProjectStageId", stageId);
        criteriaMile.andIsNull("finishDate");
     /*           criteriaMile.andNotEqualTo("finishStatus", "2");//  2 是 已完成
                criteriaMile.andNotEqualTo("finishStatus", "3");//  3 是 延迟*/
        Integer countMi = supervisorProjectMilepostService.selectCountByExample(exampleMile);

        // 查询阶段
        if (countMi == 0) {// 所有的都是已经完成
            // 更新
            /*阶段完成*/
            //String jdstatus = updategetjdStatus(stagef);
            stagef.setFinishStatus("2");
            jsonObject.put("jd_status", "2 ");
            supervisorProjectStageService.updateByPrimaryKey(stagef);
            //如果该阶段是验收阶段，那么设置项目状态为结束
            supervisorProjectService.updateProjectStatusAfterStageFinish(stagef);
            //其他监理工作不计算项目进度
            if (!"005".equals(stagef.getStageNo())) {
                String  logtext="cccccccccccccccccc";
                BigDecimal bigDecimal = supervisorProjectService.calProgress(stagef,logtext);
                jsonObject.put("progress", bigDecimal);
            }
        } else {
            String jd_status = stagef.getFinishStatus(); // 阶段完成状态
            if (jd_status.equals("0")) {
                // 未进行修改为进行中
                stagef.setFinishStatus("1");
                jsonObject.put("jd_status", "1");
                supervisorProjectStageService.updateByPrimaryKey(stagef);
            }
            if (("2".equals(milepost.getFinishStatus()) || "3".equals(milepost.getFinishStatus())) && !"005".equals(stagef.getStageNo())) {
                String  logtext="dddddddddddddddddddddd";
                BigDecimal bigDecimal = supervisorProjectService.calProgress(milepost,logtext);
                jsonObject.put("progress", bigDecimal);
            }


        }
        re.setData(jsonObject);

        return restr;

    }


    /**
     * @param stage
     * @Author:zhaoyongke
     * @Description:
     * @Date:13:06 2021/1/11
     */
    public String updategetjdStatus(SupervisorProjectStage stage) throws Exception {
        /*查询有没有延迟的里程  如果有 则 阶段延迟*/
        SupervisorProjectMilepost milepost = new SupervisorProjectMilepost();
        milepost.setSupervisorProjectStageId(stage.getId());
        milepost.setFinishStatus("3");
        int countyclc = supervisorProjectMilepostService.selectCount(milepost);
        if (countyclc > 0) {
            /*延迟*/
            return "3";
        } else {
            /*完成*/
            return "2";
        }
    }

    /**
     * @Author:zhaoyongke
     * @Description: 合并文档
     * @Date:22:36 2021/1/6
     */
    public void updatedohbwd(SupervisorProjectMilepost projectMilepost) throws Exception {
        String milepostNo = projectMilepost.getMilepostNo();
        switch (milepostNo) {
            case "031":
                updateMergeWord(projectMilepost);
                break;
            default:
        }


    }

    /**
     * @Author:zhaoyongke
     * @Description: 合并文档
     * @Date:22:36 2021/1/6
     */
    public void updateMergeWord(SupervisorProjectMilepost projectMilepost) throws Exception {
        String projectId = projectMilepost.getProjectId();
        String milepostId = projectMilepost.getId();
        SupervisorFile file = new SupervisorFile();
        file.setProjectId(projectId);
        file.setSpmId(milepostId);
        /*监理通知*/
        file.setType("091");
        List<SupervisorFile> filelist = supervisorFileService.select(file);
        for (int i = 0; i < filelist.size(); i++) {
            SupervisorFile filetarget = filelist.get(i);
            String parentId = filetarget.getId();
            /*获取该通知下的回执单*/
            SupervisorFile filehzd = new SupervisorFile();
            filehzd.setParentId(parentId);
            filehzd.setProjectId(projectId);
            filehzd.setType("111");
            List<SupervisorFile> filehzlist = supervisorFileService.select(filehzd);
            if (filehzlist.size() > 0) {
                filehzd = filehzlist.get(0);
            }
            String tzurl = filetarget.getUrl() + "";
            String hzdurl = filehzd.getUrl() + "";
            if (StringUtil.isNotBlank(tzurl) && StringUtil.isNotBlank(hzdurl)) {
                WordUtil.mergeWord(tzurl, hzdurl);
            }
        }

    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 到货验收---开箱检验
     * @Date:10:29 2020/12/4
     */
    @GetMapping(value = "dhys-kxjy")
    public String dhysKxjy(SupervisorProjectDTO dto, Model model) {
        String fileid = dto.getFileId();// 文件id
        String fbId = dto.getFbId();//分包id
        // 查询分包
        ProjectContract contract = new ProjectContract();
        contract.setId(fbId);
        contract = projectContractService.selectByPrimaryKey(contract);
        // 查询主文件
        SupervisorFile file = new SupervisorFile();
        file.setId(fileid);
        file = supervisorFileService.selectByPrimaryKey(file);

        //查询文件列表
        SupervisorFile AoFile = new SupervisorFile();
        AoFile.setProjectId(file.getProjectId());
        AoFile.setSpmId(file.getSpmId());
        AoFile.setType("040");
        AoFile.setParentId(fileid);
        List<SupervisorFile> AlistFiles = supervisorFileService.select(AoFile);

        model.addAttribute("filedto", file);
        model.addAttribute("fbId", fbId);
        model.addAttribute("contract", contract);
        model.addAttribute("list_file", AlistFiles);
        return "/supervisor/projectManager/dhys-kxjy";
    }


    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:到货验收 ---加电检验
     * @Date:15:53 2020/12/4
     */
    @GetMapping(value = "dhys-jdjy")
    public String dhysjdjy(SupervisorProjectDTO dto, Model model) {
        String fileid = dto.getFileId();// 文件id
        String fbId = dto.getFbId();//分包id
        // 查询分包
        ProjectContract contract = new ProjectContract();
        contract.setId(fbId);
        contract = projectContractService.selectByPrimaryKey(contract);
        // 查询文件
        SupervisorFile file = new SupervisorFile();
        file.setId(fileid);
        file = supervisorFileService.selectByPrimaryKey(file);

        // 加电检验
        SupervisorFile supervisorFile = new SupervisorFile();
        supervisorFile.setType("041");
        supervisorFile.setProjectId(file.getProjectId());
        supervisorFile.setSpmId(file.getSpmId());
        supervisorFile.setParentId(fileid);

        List<SupervisorFile> list_file = supervisorFileService.select(supervisorFile);
        model.addAttribute("filedto", file);
        model.addAttribute("contract", contract);
        model.addAttribute("list_file", list_file);
        return "/supervisor/projectManager/dhys-jdjy";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:监理通知回执单
     * @Date:15:17 2020/12/5
     */
    @GetMapping(value = "qt-jltz-hzd")
    public String qtjltzhzd(SupervisorProjectDTO dto, Model model) {
        String fileid = dto.getFileId();// 文件id

        // 查询监理通知文件
        SupervisorFile file = new SupervisorFile();
        file.setId(fileid);
        file = supervisorFileService.selectByPrimaryKey(file);
        //通过form表 获取 保存的分包编号 获取from Id
        String spfId = file.getLinkId();
        SupervisorProjectForms from = supervisorProjectFormsService.selectByPrimaryKey(spfId);
        //监理通知from 添加时把 承建单位项目经理  存在spf30 字段中了
        String cjXmmanager = from.getSpfF30();
        ProjectUnitConstruction construction = new ProjectUnitConstruction();
        construction.setProjectManager(cjXmmanager);
        construction.setSupervisorProjectId(file.getProjectId());
        List<ProjectUnitConstruction> listunit = projectUnitConstructionService.select(construction);
        String fbcode = listunit.get(0).getConstructionSubContractNumber();
        //通过分包编号 查询 分包信息
        // 查询分包
        ProjectContract contract = new ProjectContract();
        contract.setCode(fbcode);
        contract.setProjectId(file.getProjectId());
        contract = projectContractService.selectOne(contract);

        // 查询该类型的文件 初始化 111 回执单
        SupervisorFile supervisorFile = new SupervisorFile();
        // 回执单
        supervisorFile.setType("111");
        supervisorFile.setProjectId(file.getProjectId());
        supervisorFile.setParentId(fileid);
        supervisorFile.setSpmId(file.getSpmId());
        List<SupervisorFile> list_file = supervisorFileService.select(supervisorFile);
        model.addAttribute("filedto", file);
        model.addAttribute("contract", contract);
        model.addAttribute("list_file", list_file);
        model.addAttribute("pcId", contract.getId());
        return "/supervisor/projectManager/qt-jltz-hzd";
    }

    /**
     * @param filedata
     * @param dto
     * @param request
     * @Author:zhaoyongke
     * @Description: 针对表单中存在上传图片  比如 监理总结报告
     * @Date:9:32 2020/12/7
     */
    @RequestMapping(value = "/addFileImage", method = RequestMethod.POST)
    @ResponseBody
    public JsonUtil addFileImage(@RequestParam(value = "file", required = false) MultipartFile filedata, SupervisorProjectDTO dto, HttpServletRequest request) {

        JsonUtil re = new JsonUtil();
        // 当前用户信息
        String userid = CommonUtil.getUserId();
        String spmid = dto.getSpmId();// 里程id
        String stageId = dto.getStageId();//阶段id
        String fs_status = request.getParameter("fs_status");// 上传的时候 对应的状态
        String projectid = dto.getId();// 项目id
        String fbId = request.getParameter("fbId");// 分包表id
        LoadType loadType = uploadUtil.upload(filedata, "1");
        String filename = filedata.getOriginalFilename();
        // 保存文件表
        SupervisorFile filedto = new SupervisorFile();
        filedto.setFileName(filename);
        filedto.setFileType(loadType.getSuffix());
        filedto.setType(dto.getType());
        filedto.setCreateBy(userid);
        filedto.setCreateDate(new Date());
        filedto.setUrl(loadType.getFilePath());
        if (null != fbId && !"".equals(fbId)) {
            filedto.setPcId(fbId);// 分包id
        }
        filedto.setParentId(dto.getParentId());
        filedto.setPositionName(dto.getPositionName());
        filedto.setProjectId(projectid);// 项目id
        filedto.setSpmId(spmid);// 里程id
        supervisorFileService.insert(filedto);
        supervisorFileService.setFilePathDics(filedto);
        re.setMsg(filename);
        re.setFlag(true);
        return re;
    }

    /**
     * @param filedata
     * @param dto
     * @param request
     * @Author:zhaoyongke
     * @Description: 上传附件
     * @Date:9:59 2021/1/14
     */
    @RequestMapping(value = "/addFileFj", method = RequestMethod.POST)
    @ResponseBody
    public JsonUtil addFileFj(@RequestParam(value = "file", required = false) MultipartFile filedata, SupervisorProjectDTO dto, HttpServletRequest request) {

        JsonUtil re = new JsonUtil();
        // 当前用户信息
        String filename = null;
        SupervisorFile filedto = null;
        try {
            String userid = CommonUtil.getUserId();
            String spmid = dto.getSpmId();// 里程id
            String stageId = dto.getStageId();//阶段id
            String projectid = dto.getId();// 项目id
            String fbId = request.getParameter("fbId");// 分包表id
            LoadType loadType = uploadUtil.upload(filedata, "1");
            filename = filedata.getOriginalFilename();
            // 保存文件表
            filedto = new SupervisorFile();
            if ("115".equals(dto.getType())) {
                /*监理工作总结报告*/
                filedto.setFileName(loadType.getFileName());
            } else {
                filedto.setFileName(filename);
            }

            filedto.setFileType(loadType.getSuffix());
            filedto.setType(dto.getType());
            filedto.setCreateBy(userid);
            filedto.setCreateDate(new Date());
            filedto.setUrl(loadType.getFilePath());
            if (null != fbId && !"".equals(fbId)) {
                filedto.setPcId(fbId);// 分包id
            }
            filedto.setParentId(dto.getParentId());
            if (!"113".equals(dto.getType())) {
                /*签章图片不保存 阶段和里程*/
                filedto.setSpmId(spmid);// 里程id
                filedto.setStageId(stageId);
            } else {
                /*删除之前的签章图片*/
                SupervisorFile file = new SupervisorFile();
                file.setProjectId(projectid);
                file.setType("113");
                List<SupervisorFile> filelist = supervisorFileService.select(file);
                for (int i = 0; i < filelist.size(); i++) {
                    File fileimage = new File(filelist.get(i).getUrl());
                    if (fileimage.exists()) {
                        fileimage.delete();
                        System.out.println("删除成功");
                    }
                    supervisorFileService.deleteByPrimaryKey(filelist.get(i));
                }
            }
            filedto.setProjectId(projectid);// 项目id
            supervisorFileService.insert(filedto);
            supervisorFileService.setFilePathDics(filedto);
            re.setData(filedto.getUrl());
            if ("115".equals(dto.getType())) {
                re.setMsg(loadType.getFileName());
            } else {
                re.setMsg(filename);
            }

            re.setFlag(true);
            return re;
        } catch (Exception e) {
            e.printStackTrace();
            re.setFlag(false);
        }

        return re;
    }

    /**
     * @param id
     * @param request
     * @param response
     * @Author:Zhangshuo
     * @Description:
     * @Date:15:20 2020-12-14
     */
    @RequestMapping(value = "/export")
    public void downloadxls(@RequestParam("id") String id, @RequestParam("name") String name, HttpServletRequest request, HttpServletResponse response) throws IOException {
        SupervisorFileDTO dto = new SupervisorFileDTO();
        dto.setProjectId(id);
        /*查询监理文档---文件字典level4为1*/
        List<SupervisorFileDTO> AlstFiles = supervisorFileService.selectFileList(dto);
        // 获取项目名称
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(id);
        /*项目名称*/
        String projectName = project.getProjectName();
        String AsOutPath = tempPath + File.separator + name + DateUtil.getCurrentDateTimeStringNoSpliter() + ".zip";
        ZipOutputStream AzOut = new ZipOutputStream(new FileOutputStream(AsOutPath));
        try {
            for (SupervisorFileDTO AoFile : AlstFiles) {
                String AsTmpFileName = AoFile.getUrl();
                File AfTmp = new File(AsTmpFileName);
                if (AfTmp.exists()) {
                    Boolean isGl = true;
                    //检查记录和旁站记录照片 到货验收和隐蔽验收照片不导出
                    if ("036".equals(AoFile.getType()) || "037".equals(AoFile.getType()) || "106".equals(AoFile.getType()) || "043".equals(AoFile.getType()) || "047".equals(AoFile.getType())) {
                        Image image = ImageIO.read(AfTmp);
                        if (image != null) {
                            isGl = false;
                        }
                    }
                    if (isGl) {
                        String path = AfTmp.getPath();
                        String fileName = AfTmp.getName();
                        String dir = path.substring(path.indexOf(projectName), path.length()).replace(projectName + "" + File.separator, "").replace(File.separator + "" + fileName, "");
                        ZipUtils.doCompress(new File(AsTmpFileName), AzOut, dir);
                    }

                }
            }
        } finally {
            AlstFiles.clear();
            AlstFiles = null;
            AzOut.close();
        }
        ExportFileUtil.exportFile(response, request, AsOutPath);
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 文档统计
     * @Date:16:10 2020/12/15
     */
    @GetMapping(value = "viewTj")
    public String viewTj(SupervisorProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/supervisor/projectManager/viewTj";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:项目大事记
     * @Date:16:55 2021/1/11
     */
    @GetMapping(value = "viewBigEvent")
    public String viewBigEvent(SupervisorProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        // 项目经理才有权限修改 大事记
        String managerPerson = project.getProjectManagerPerson();
        String userId = CommonUtil.getUserId();
        if (userId.equals(managerPerson)) {
            model.addAttribute("show", "1");
        }
        return "/supervisor/projectManager/viewBigEvent";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:用章记录
     * @Date:11:35 2021/1/12
     */
    @GetMapping(value = "viewSealReocrd")
    public String viewSealReocrd(SupervisorProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/supervisor/projectManager/viewSealRecord";
    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:查询大事记
     * @Date:18:47 2021/1/11
     */
    @GetMapping(value = "queryBigEvent")
    @ResponseBody
    public ReType viewBigEvent(ProjectBigEventDTO dto, Model model, String page, String limit) {
        List<ProjectBigEventDTO> tList = null;
        Page<ProjectBigEventDTO> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        try {
            tList = projectBigEventService.selectProjectBigEvent(dto);
        } catch (MyException e) {
            e.printStackTrace();
        }
        return new ReType(tPage.getTotal(), tList);
    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:查询用章记录
     * @Date:11:51 2021/1/12
     */
    @GetMapping(value = "querySealRecord")
    @ResponseBody
    public ReType querySealRecord(ProjectSealRecordDTO dto, Model model, String page, String limit) {
        List<ProjectSealRecordDTO> tList = null;
        Page<ProjectSealRecordDTO> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        try {
            tList = projectSealRecordService.selectProjectSealRecordList(dto);
        } catch (MyException e) {
            e.printStackTrace();
        }
        return new ReType(tPage.getTotal(), tList);
    }

    /**
     * @Author:zhaoyongke
     * @Description: 更新大事记
     * @Date:18:47 2021/1/11
     */
    @PostMapping(value = "updateBigEvent")
    @ResponseBody
    public JsonUtil updateBigEvent(ProjectBigEventDTO dto) {
        JsonUtil re = new JsonUtil();
        try {
            String id = dto.getProEventId();
            String operDate = dto.getOperDate();
            ProjectBigEvent event = projectBigEventService.selectByPrimaryKey(id);
            event.setOldOperDate(event.getOperDate());
            event.setOperDate(operDate);
            event.setModifyBy(CommonUtil.getUserId());
            event.setModifyDate(DateUtil.getCurrentDateString());
            projectBigEventService.updateByPrimaryKey(event);
            re.setFlag(true);
            re.setMsg("擦作成功");
        } catch (Exception e) {
            e.printStackTrace();
            re.setFlag(false);
            re.setMsg("擦作失败：" + e.getMessage());
        }
        return re;
    }

    /**
     * @param dto
     * @Author:zhaoyongke
     * @Description:取消修改
     * @Date:17:41 2021/1/11
     */
    @PostMapping(value = "updateCancleBigEvent")
    @ResponseBody
    public JsonUtil updateCancleBigEvent(ProjectBigEventDTO dto) {
        JsonUtil re = new JsonUtil();
        try {
            String id = dto.getProEventId();
            ProjectBigEvent event = projectBigEventService.selectByPrimaryKey(id);
            event.setOperDate(event.getOldOperDate());
            event.setModifyBy(CommonUtil.getUserId());
            event.setModifyDate(DateUtil.getCurrentDateString());
            projectBigEventService.updateByPrimaryKey(event);
            re.setFlag(true);
            re.setMsg("擦作成功");
        } catch (Exception e) {
            e.printStackTrace();
            re.setFlag(false);
            re.setMsg("擦作失败：" + e.getMessage());
        }
        return re;
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 承建选择付款次数
     * @Date:10:15 2020/12/19
     */
    @GetMapping(value = "openZfcs")
    public String openZfcs(SupervisorProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        String fileId = dto.getFileId();
        // 查询付款次数
        SupervisorProjectPay supervisorProjectPay = new SupervisorProjectPay();
        supervisorProjectPay.setSppPrjid(projectId);
        List<SupervisorProjectPay> listpay = supervisorProjectPayService.select(supervisorProjectPay);
        //获取分包Id
        SupervisorFile file = supervisorFileService.selectByPrimaryKey(fileId);
        String pcId = file.getPcId();
        String type = file.getType();
        String code = "";
        if ("108".equals(type) || "087".equals(type)) {
            //承建单位付款申请
            //根据分包Id 查询分包编号
            ProjectContract projectContract = projectContractService.selectByPrimaryKey(pcId);
            code = projectContract.getCode();
            //根据分包code 查询承建单位Id
            ProjectUnitConstruction projectUnitConstruction = new ProjectUnitConstruction();
            projectUnitConstruction.setSupervisorProjectId(projectId);
            projectUnitConstruction.setConstructionSubContractNumber(code);
            projectUnitConstruction = projectUnitConstructionService.selectOne(projectUnitConstruction);
            if (projectUnitConstruction != null) {
                model.addAttribute("id", projectUnitConstruction.getId());
            }
            model.addAttribute("zftype", "1");
        } else if ("109".equals(type) || "088".equals(type)) {
            //监理单位付款申请
            model.addAttribute("zftype", "2");
        }
        model.addAttribute("projectId", projectId);
        model.addAttribute("fileId", fileId);
        model.addAttribute("fbcode", code);
        model.addAttribute("listpay", listpay);

        return "/supervisor/projectManager/openZfcs";
    }


    /**
     * @param project
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 统计文档类型
     * @Date:16:49 2020/12/15
     */
    @GetMapping(value = "showviewTjList")
    @ResponseBody
    public ReType showviewTjList(SupervisorProjectDTO project, Model model, int page, int limit) {
        String projectId = project.getProjectId();
        List<SupervisorFileDTO> tList = null;
        Page<SupervisorFileDTO> tPage = PageHelper.startPage(page, limit);
        try {
            SupervisorFileDTO dto = new SupervisorFileDTO();
            dto.setProjectId(projectId);
            tList = supervisorFileService.getFileCountByType(dto);
        } catch (MyException e) {
            e.printStackTrace();
        }
        return new ReType(tPage.getTotal(), tList);
    }

    /**
     * @param project
     * @Author:zhaoyongke
     * @Description: 导出数据
     * @Date:18:28 2020/12/15
     */
    @GetMapping(value = "getTjData")
    @ResponseBody
    public JsonUtil getTjData(SupervisorProjectDTO project) {
        JsonUtil re = new JsonUtil();
        String projectId = project.getProjectId();
        if (StringUtils.isEmpty(projectId)) {
            return JsonUtil.error("获取数据失败");
        } else {
            SupervisorFileDTO dto = new SupervisorFileDTO();
            dto.setProjectId(projectId);
            List<SupervisorFileDTO> tList = supervisorFileService.getFileCountByType(dto);
            re.setFlag(true);
            re.setData(tList);
        }
        return re;
    }

    /**
     * @Author:zhaoyongke
     * @Description:获取项目大事记 导出
     * 2021年11月25日15:07:35 修改为@Excel注解导出excel
     * @Date:18:39 2021/1/11
     */
    @GetMapping(value = "getBigEventData")
    @ResponseBody
    public void getBigEventData(ProjectBigEventDTO bigEvent, HttpServletResponse response) {
        String projectId = bigEvent.getProjectId();
        try {
            SupervisorProject supervisorProject = supervisorProjectService.selectByPrimaryKey(projectId);
            String name = supervisorProject.getProjectName() + "_项目大事记";
            List<ProjectBigEventDTO> tList = projectBigEventService.selectProjectBigEvent(bigEvent);
            List<ExProjectBigEvent> temp = new ArrayList<>();
            for (int i = 0; i < tList.size(); i++) {
                ProjectBigEventDTO projectBigEventDTO = tList.get(i);
                ExProjectBigEvent exProjectBigEvent = new ExProjectBigEvent();
                exProjectBigEvent.setXh(String.valueOf(i+1));
                exProjectBigEvent.setStageName(projectBigEventDTO.getStageName());
                exProjectBigEvent.setMilePostName(projectBigEventDTO.getMilePostName());
                exProjectBigEvent.setOperDate(projectBigEventDTO.getOperDate());
                temp.add(exProjectBigEvent);
            }
            Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(name,name), ExProjectBigEvent.class, temp);
            response.setCharacterEncoding("UTF-8");
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(name+".xls", "UTF-8"));
            workbook.write(response.getOutputStream());
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * @param pFileId
     * @param request
     * @param response
     * @Description:
     * @Author:Zhangshuo
     * @Date:2:37 2020-12-19
     */
    @RequestMapping(value = "/img")
    public void loadimg(@RequestParam("fid") String pFileId, HttpServletRequest request, HttpServletResponse response) throws IOException {
        if (StringUtil.isNotBlank(pFileId)) {
            SupervisorFile supervisorFile = supervisorFileService.selectByPrimaryKey(pFileId);
            String AsFileName = supervisorFile.getUrl();
            ExportFileUtil.exportFile(response, request, AsFileName);
        }
    }


    /**
     * @param projectdto
     * @Author:zhaoyongke
     * @Description: 工程款支付
     * @Date:11:44 2020/12/19
     */
    @RequestMapping(value = "/saveFkje", method = RequestMethod.POST)
    @ResponseBody
    public JsonUtil saveFkje(SupervisorProjectDTO projectdto) {
        String type = projectdto.getType();
        JsonUtil re = new JsonUtil();
        try {
            //承建单位Id
            String cjId = projectdto.getId();
            //项目Id
            String projectId = projectdto.getProjectId();
            //文件Id
            String fileId = projectdto.getFileId();
            SupervisorFile file = supervisorFileService.selectByPrimaryKey(fileId);
            if ("1".equals(type)) {
                if (StringUtils.isEmpty(cjId)) {
                    return JsonUtil.error("获取数据失败");
                }
                savePayCj(cjId, projectdto, file);
            }

            re.setMsg("操作成功");
            re.setFlag(true);
        } catch (Exception e) {
            re.setMsg("操作失败" + e.getMessage());
            re.setFlag(false);
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

        }

        return re;


    }

    /**
     * @param cjId
     * @param projectdto
     * @param file
     * @Author:zhaoyongke
     * @Description: 承建付款申请保存
     * @Date:17:54 2020/12/29
     */
    public void savePayCj(String cjId, SupervisorProjectDTO projectdto, SupervisorFile file) {

        //承建付款
        ProjectUnitConstruction unitConstruction = projectUnitConstructionService.selectByPrimaryKey(cjId);
        //承建已支付金额
        String paymoney = unitConstruction.getPayMoney();
        if (paymoney == null || "".equals(paymoney)) {
            paymoney = "0.0";
        }
        // 获取前台传入的金额
        String addmoney = projectdto.getPaymoney();
        BigDecimal je = new BigDecimal(paymoney);
        BigDecimal addje = new BigDecimal(addmoney);
        BigDecimal jsje = je.add(addje);
        String jestr = jsje.stripTrailingZeros().toPlainString();
        ;
        unitConstruction.setPayMoney(jestr);
        projectUnitConstructionService.updateByPrimaryKey(unitConstruction);
        //支付记录需要记录（后期统计需要）
        SupervisorPayRecord payRecord = new SupervisorPayRecord();
        //原金额
        payRecord.setOldMoney(paymoney);
        //支付金额
        payRecord.setZfMoney(addmoney);
        // 承建付款申请 002 监理付款申请 002
        payRecord.setZfType("001");
        //项目Id
        payRecord.setProjectId(file.getProjectId());
        //阶段Id
        payRecord.setStageId(file.getStageId());
        //里程Id
        payRecord.setSpmId(file.getSpmId());
        //项目支付次数Id
        payRecord.setSppId("");
        //文件Id
        payRecord.setFileId(file.getId());
        supervisorPayRecordService.insertSelective(payRecord);

    }

    /**
     * @Author:zhaoyongke
     * @Description: 监理付款申请保存
     * @Date:17:55 2020/12/29
     */
    @RequestMapping(value = "/savePayJL", method = RequestMethod.POST)
    @ResponseBody
    public JsonUtil savePayJL(SupervisorPayRecord payRecord) throws Exception {
        JsonUtil re = new JsonUtil();
        String projectId = payRecord.getProjectId();
        //监理付款申请
        SupervisorProject supervisorProject = supervisorProjectService.selectByPrimaryKey(projectId);
        String jlpayMoney = supervisorProject.getJlPayMoney();
        if (jlpayMoney == null || "".equals(jlpayMoney)) {
            jlpayMoney = "0.0";
        }
        String jlInvoiceMoney = supervisorProject.getJlInvoiceMoney();
        if (jlInvoiceMoney == null || "".equals(jlInvoiceMoney)) {
            jlInvoiceMoney = "0.0";
        }
        // 处理支付金额
        String addPaymoney = payRecord.getZfMoney();
        BigDecimal je = new BigDecimal(jlpayMoney);
        BigDecimal addje = new BigDecimal(addPaymoney);
        BigDecimal jsje = je.add(addje);
        String jestr = jsje.stripTrailingZeros().toPlainString();
        supervisorProject.setJlPayMoney(jestr);
        // 处理发票金额
        String addFpmoney = payRecord.getFpMoney();
        BigDecimal fp = new BigDecimal(jlInvoiceMoney);
        BigDecimal addfp = new BigDecimal(addFpmoney);
        BigDecimal jsfp = fp.add(addfp);
        String jsfpstr = jsfp.stripTrailingZeros().toPlainString();
        supervisorProject.setJlInvoiceMoney(jsfpstr);
        supervisorProjectService.updateByPrimaryKey(supervisorProject);
        //支付表Id 记录支付次数
        String sppId = payRecord.getSppId();
        String js_status = "";
        if(StringUtil.isBlank(supervisorProject.getFkType())){
            re.setMsg("付款方式为空");
            re.setFlag(false);
            return re;
        }
        // 处理付款及时性（提前 按时 延期）
        if ("1".equals(supervisorProject.getFkType())) {
            // 节点
            js_status = getpayJsStatus(projectId, sppId);
        } else {
            js_status = getpayJsStatusByDate(sppId);
        }
        //支付记录需要记录（后期统计需要）
        //原金额
        payRecord.setOldMoney(jlpayMoney);
        //原发票金额
        payRecord.setOldFpMoney(jlInvoiceMoney);
        //项目支付次数Id
        payRecord.setSppId(sppId);
        /*付款及时性*/
        payRecord.setJsStatus(js_status);
        supervisorPayRecordService.insertSelective(payRecord);

        re.setMsg("操作成功");
        re.setFlag(true);
        return re;
    }

    /**
     * @param
     * @Author:hanchen
     * @Description: 处理汇款及时性
     * @Date:18:38 2020/12/29
     */
    public String getpayJsStatusByDate(String sppId) {
        /*及时性  001 提前 002 按时 003 延期*/
        //查询该支付次数对应的里程
        SupervisorProjectPay projectPay = supervisorProjectPayService.selectByPrimaryKey(sppId);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String jsStatus = "";
        Integer i = projectPay.getPayDate().compareTo(formatter.format(new Date()));
        if (i == 0) {
            jsStatus = "002";
        } else if (i < 0) {
            jsStatus = "003";
        } else {
            jsStatus = "001";
        }
        return jsStatus;
    }

    /**
     * @param
     * @Author:zhaoyongke
     * @Description: 处理汇款及时性
     * @Date:18:38 2020/12/29
     */
    public String getpayJsStatus(String projectId, String sppId) throws Exception {
        /*及时性  001 提前 002 按时 003 延期*/
        String jsStatus = "";
        // 处理付款及时性（提前 按时 延期）
        SupervisorProjectMilepostDTO su = new SupervisorProjectMilepostDTO();
        su.setProjectId(projectId);
        List<SupervisorProjectMilepostDTO> AlistMilePost = supervisorProjectMilepostService.selectProjectmilepost(su);
        //查询该支付次数对应的里程
        SupervisorProjectPay projectPay = supervisorProjectPayService.selectByPrimaryKey(sppId);
        String node = projectPay.getSppNode();
        if (StringUtil.isBlank(node)) {
            throw new Exception("获取付款节点失败");
        }
        // 后台配置的付款节点，不参与 回款及时性的判断 ，查询动态判断
        BaseDict baseDict = new BaseDict();
        baseDict.setBadtTypecode("ZHIBAO");
        List<BaseDict> baseDicts = baseDictService.select(baseDict);
        if (baseDicts != null && baseDicts.size() > 0){
            for (BaseDict dict : baseDicts) {
                if (dict.getBadtCode().equals(node)){
                    return "";
                }
            }
        }
//        if ("060".equals(node) || "061".equals(node) || "062".equals(node)){
//            return "";
//        }
        SupervisorProjectMilepost milepostnew = new SupervisorProjectMilepost();
        milepostnew.setMilepostNo(node);
        milepostnew.setProjectId(projectId);
        List<SupervisorProjectMilepost> milepostcurr = supervisorProjectMilepostService.select(milepostnew);
        String currMilepostId = milepostcurr.get(0).getId();
        //完成状态  0 未开始  1 进行中  2  已完成   3   已超时
        String finishStatus = milepostcurr.get(0).getFinishStatus();
        String finishDatestr = milepostcurr.get(0).getFinishDate();
        if (!"2".equals(finishStatus)) {
            jsStatus = "001";
            return jsStatus;
        }
        // 获取该里程下一个里程
        SupervisorProjectMilepost nexsMilePost = null;
        for (int i = 0; i < AlistMilePost.size(); i++) {
            SupervisorProjectMilepost milepost = AlistMilePost.get(i);
            String milepostId = milepost.getId();
            if (currMilepostId.equals(milepostId)) {
                // 获取下一个元素
                int y = i + 1;
                if (y < AlistMilePost.size()) {
                    nexsMilePost = AlistMilePost.get(y);
                }
                break;
            }
        }
        if (nexsMilePost != null) {
            String nextFinshStatus = nexsMilePost.getFinishStatus();
            /*当前节点已经完成，下一节点未完成 为及时*/
            if (!"2".equals(nextFinshStatus)) {
                jsStatus = "002";
            } else {
                /*当前节点已经完成，下一节点已经完成 为延期*/
                jsStatus = "003";
            }
        } else {
            /*没有下一节点，当前节点+30天*/
            Date finishDate = DateUtil.parseDate(finishDatestr);
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(finishDate);
            calendar.add(Calendar.DATE, 30);
            /*30天后日期*/
            Date datenext30 = new Date(calendar.getTimeInMillis());
            String datenext30str = DateUtil.formatDate(datenext30, "yyyy-MM-dd HH:mm:ss");
            String datecurrstr = DateUtil.formatDate(DateUtil.getCurrentDateTime(), "yyyy-MM-dd HH:mm:ss");
            /*30天之内为及时*/
            if (DateUtil.compare(datecurrstr, datenext30str)) {
                jsStatus = "002";
            } else {
                jsStatus = "003";
            }
        }


        return jsStatus;
    }

    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 获取阶段里程状态
     * @Date:14:52 2020/12/30
     */
    @RequestMapping(value = "/getLcJdStatus", method = RequestMethod.GET)
    @ResponseBody
    public JsonUtil getLcJdStatus(Model model, HttpServletRequest request) {
        JsonUtil re = new JsonUtil();
        JSONObject jsonObject = new JSONObject();
        String lcId = request.getParameter("lcId");
        String jdId = request.getParameter("jdId");
        SupervisorProjectMilepost milepost = supervisorProjectMilepostService.selectByPrimaryKey(lcId);
        String lcfinsihstatus = milepost.getFinishStatus();
        SupervisorProjectStage stage = supervisorProjectStageService.selectByPrimaryKey(jdId);
        String jdfinsihstatus = stage.getFinishStatus();
        jsonObject.put("lc_status", lcfinsihstatus);
        jsonObject.put("jd_status", jdfinsihstatus);
        re.setFlag(true);
        re.setData(jsonObject);
        return re;
    }

    /**
     * @param project
     * @Author:zhaoyongke
     * @Description:流程是否结束
     * @Date:14:06 2021/2/22
     */
    @GetMapping(value = "getLcIsEnd")
    @ResponseBody
    public JsonUtil getLcIsEnd(SupervisorProjectDTO project) {
        JsonUtil re = new JsonUtil();
        String fileId = project.getFileId();
        SupervisorFile file = supervisorFileService.selectByPrimaryKey(fileId);
        Boolean isEnd = lcIsEnd(file);
        if (!isEnd) {
            re.setFlag(false);
            re.setMsg("请流程结束后再操作");
            return re;
        }
        String bsStatus = file.getBsStatus();
        if ("1".equals(bsStatus)) {
            re.setData("1");
        } else {
            re.setData("0");
        }
        re.setFlag(true);
        return re;
    }

    /**
     * @param file
     * @Author:zhaoyongke
     * @Description:流程是否结束
     * @Date:14:23 2021/2/22
     */
    public Boolean lcIsEnd(SupervisorFile file) {
        Boolean islcEnd = false;
        String type = file.getType();
        String lcstatus = file.getLcStatus();
        BaseDict dict = DictUtil.getDictByCode(DictTypes.WJ, type);
        String lcsl = dict.getBadtLevel3();
        if ("3".equals(lcsl) || "2".equals(lcsl)) {
            /*内部 外部流程*/
            if ("5".equals(lcstatus) || "6".equals(lcstatus)) {
                islcEnd = true;
            }
        } else if ("1".equals(lcsl)) {
            // 内部流程
            if ("2".equals(lcstatus) || "3".equals(lcstatus)) {
                islcEnd = true;
            }
        }
        return islcEnd;
    }

    /**
     * 查询图片文档预览用
     *
     * @param supervisorFile
     * @return
     */
    @GetMapping("selectfile")
    @ResponseBody
    public SupervisorFile selectfile(SupervisorFile supervisorFile) {
        SupervisorFile sf = supervisorFileService.selectByPrimaryKey(supervisorFile);
        String imgUrl = sf.getUrl();
        String uploadPath = uploadUtil.getUploadPath();
        imgUrl = imgUrl.substring(uploadPath.length());
        imgUrl = File.separator + "itfile" + File.separator + imgUrl;
        sf.setUrl(imgUrl);
        return sf;
    }

    /**
     * @param project
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:
     * @Date:16:45 2021/3/13
     */
    @ApiOperation(value = "/showProjectGxList", httpMethod = "GET", notes = "展示供需项目")
    @GetMapping(value = "/showProjectGxList")
    @ResponseBody
    public ReType showProjectList(SupplierProjectDTO project, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        project.setStatus("004");
        if (StringUtil.isNotBlank(project.getKeyword())) {
            project.setProjectName(project.getKeyword());
        }
        project.setProjectType("001");
        //项目经理是自己的
//        project.setJlManagerPerson(CommonUtil.getUserId());
        List<SupplierProjectDTO> data = supplierProjectManagerService.selectListGx(project);
        for (int i = 0; i < data.size(); i++) {
            SupplierProjectDTO dto = (SupplierProjectDTO) data.get(i);
            String pubComType = dto.getPubComType();
            String publishBy = dto.getPublishBy();
            // 中标人
            String zbBy = dto.getZbBy();
            String supAcceptId = dto.getSupAcceptId();
            if(StringUtil.isNotBlank(supAcceptId)){
                //客户名称
                String owerCompany = dto.getOwerCompany();
                SupplierProjectAccept accept = supplierProjectAcceptService.selectByPrimaryKey(supAcceptId);

                String companyId = accept.getCompanyId();
                // 获取业主单位
                String companyName = getFbdwByUser(publishBy, owerCompany);


                data.get(i).setCompanyName(companyName);
                data.get(i).setZbCompany(companyId);
                data.get(i).setJlManagerPerson(accept.getJlManagerPerson());
                ProjectPlaceDTO pacedto = new ProjectPlaceDTO();
                pacedto.setSupProjectId(dto.getSupProjectId());
                pacedto.setType("001");
                List<ProjectPlaceDTO> listpalce = projectPlaceService.selectPlace(pacedto);
                for (int y = 0; y < listpalce.size(); y++) {
                    String province = listpalce.get(y).getProvince();
                    List<SysRegion> citylist1 = sysRegionService.selectSysRegionByParentCode(province);
                    listpalce.get(y).setCitys(citylist1);
                    String city = listpalce.get(y).getCity();
                    List<SysRegion> countylist2 = sysRegionService.selectSysRegionByParentCode(city);
                    listpalce.get(y).setCountys(countylist2);
                }
                data.get(i).setProjectPlacedtos(listpalce);
            }



            // 中标单位
     /*        String  zbCompanyName=getAcceptdwByUser(accept);
             data.get(i).setZbCompanyName(zbCompanyName);*/

        }
        re.setPageNum(Long.valueOf(page));
        re.setCount(data.size());
        re.setData(data);

        return re;

    }

    /**
     * @param userId
     * @Author:zhaoyongke
     * @Description: 获取发布单位
     * @Date:10:24 2021/4/7
     */
    public String getFbdwByUser(String userId, String khmc) {
        String companyName = "";
        SysUser sysUser = sysUserService.selectByPrimaryKey(userId);
        String source="";
        if(sysUser!=null){
             source = sysUser.getSource();
            if ("001".equals(source)) {
                if (StringUtil.isNotBlank(khmc)) {
                    // 获取选择的oa 接口中的数据
                    companyName = khmc;
                } else {
                    // 正中人员
                    String companyId = sysUser.getCompanyName();
                    BaseCompany baseCompany = baseCompanyService.selectByPrimaryKey(companyId);
                    companyName = baseCompany.getBcName();
                }

            } else {

                companyName = sysUser.getCompanyName();
            }
        }

        return companyName;

    }

    /**
     * @Author:zhaoyongke
     * @Description: 获取应接单位
     * @Date:10:24 2021/4/7
     */
    public String getAcceptdwByUser(SupplierProjectAccept accept) {
        String acceptBy = accept.getAcceptBy();
        SysUser sysUser = sysUserService.selectByPrimaryKey(acceptBy);
        String comType = accept.getComType();
        String companyName = "";
        if ("001".equals(comType)) {
            BaseCompany baseCompany = baseCompanyService.selectByPrimaryKey(accept.getCompanyId());
            companyName = baseCompany.getBcName();

        } else {
            companyName = sysUser.getCompanyName();
        }
        return companyName;

    }

    /**
     * @Author:mr.hanchen
     * @Description:修改记录
     * @param id
     * @param model
     * @param page
     * @param limit
     * @Date:13:21 2021/7/2
     */
    @ResponseBody
    @RequestMapping("/gerRecordListHk")
    public ReType gerRecordListHk(String id, Model model, int page, int limit) {
        List<SupervisorPayRecordDTO> tList = null;
        Page<SupervisorPayRecordDTO> tPage = PageHelper.startPage(page, limit);
        try {
            SupervisorProjectDTO project = new SupervisorProjectDTO();
            project.setId(id);
            tList = supervisorPayRecordService.selectHk(project);
        } catch (MyException e) {
            e.printStackTrace();
        }
        return new ReType(tPage.getTotal(), tList);
    }

    /**
     * @Author:mr.hanchen
     * @Description:修改记录
     * @param id
     * @Date:13:21 2021/7/5
     */
    @ResponseBody
    @RequestMapping("/gerRecordHk")
    public SupervisorPayRecordDTO gerRecordHk(String id) {
        SupervisorPayRecordDTO  tList = supervisorPayRecordService.selectHkById(id);
        SupervisorProjectPayDTO projectPayDTO = new SupervisorProjectPayDTO();
        projectPayDTO.setSppPrjid(tList.getProjectId());
        List<SupervisorProjectPayDTO> suProjectPay = supervisorProjectPayService.selectSupervisorProjectPay(projectPayDTO);
        for (SupervisorProjectPayDTO jc:
                suProjectPay) {
            jc.setSppNo(getInteger(jc.getSppNo()));
        }
        tList.setSupervisorProjectPayDTOS(suProjectPay);
        return tList;
    }

    /**
     * 小数点前面部分
     * @param num
     * @return
     */
    public static String getInteger(String num){
        String STR_UNIT[] = {"","拾","佰","仟","万","拾","佰","仟","亿"};
        String STR_NUMBER[] = {"零","一","二","三","四","五","六","七","八","九"};
        if (num.indexOf(".") != -1){
            num = num.substring(0, num.indexOf("."));
        }
        num = new StringBuffer(num).reverse().toString();
        StringBuffer temp = new StringBuffer();
        for (int i=0; i<num.length(); i++){
            temp.append(STR_UNIT[i]);
            temp.append(STR_NUMBER[num.charAt(i)-48]);
        }
        num = temp.reverse().toString();

        while (num.indexOf("零零") != -1 || num.indexOf("零佰") != -1 || num.indexOf("零仟") != -1 || num.indexOf("零万") != -1 || num.indexOf("零亿") != -1 || num.indexOf("亿万") != -1 || num.indexOf("零拾") != -1) {
            num = numReplace(num, "零拾", "零");
            num = numReplace(num, "零佰", "零");
            num = numReplace(num, "零仟", "零");
            num = numReplace(num, "零万", "万");
            num = numReplace(num, "零亿", "亿");
            num = numReplace(num, "零零", "零");
            num = numReplace(num, "亿万", "亿");
            if (num.lastIndexOf("零") == num.length() - 1) {
                num = num.substring(0, num.length() - 1);
            }
        }

        return num;
    }
    public static String numReplace(String num, String oldUnit, String newUnit){
        num = num.replaceAll(oldUnit,newUnit);
        return num;
    }

    /**
     * @Author:mr.hanchen
     * @Description:保存是否到账
     * @param dto
     * @Date:13:21 2021/7/5
     */
    @ResponseBody
    @RequestMapping("/updateDz")
    public JsonUtil updateDz(SupervisorPayRecordDTO dto) {
        JsonUtil json = new JsonUtil();
        json.setFlag(false);
        try {
            SupervisorPayRecord supervisorPayRecord = new SupervisorPayRecord();
            supervisorPayRecord.setPayId(dto.getPayId());
            supervisorPayRecord = supervisorPayRecordService.selectByPrimaryKey(supervisorPayRecord);
            BigDecimal money = null;
            if("".equals(supervisorPayRecord.getArrivalMoney()) || supervisorPayRecord.getArrivalMoney() == null){
                supervisorPayRecord.setArrivalMoney(dto.getArrivalMoney());
                money = new BigDecimal(dto.getArrivalMoney());
            }else{
                supervisorPayRecord.setArrivalMoney(supervisorPayRecord.getArrivalMoney()+","+dto.getArrivalMoney());
                String[] str = supervisorPayRecord.getArrivalMoney().split(",");
                for(int x = 0;x<str.length;x++){
                    if(x==0){
                        money = new BigDecimal(str[x]);
                    }else{
                        money = money.add(new BigDecimal(str[x]));
                    }

                }
            }
            if("".equals(supervisorPayRecord.getArrivalDate()) || supervisorPayRecord.getArrivalDate() == null){
                supervisorPayRecord.setArrivalDate(dto.getArrivalDate());
            }else{
                supervisorPayRecord.setArrivalDate(supervisorPayRecord.getArrivalDate()+","+dto.getArrivalDate());
            }
            BigDecimal bigDecimal = new BigDecimal(supervisorPayRecord.getZfMoney());
            BigDecimal bigDecimal1 = money.multiply(new BigDecimal(100));
            BigDecimal bigDecimal2 = bigDecimal1.divide(bigDecimal, 2, BigDecimal.ROUND_HALF_UP);
            String arrivalMoney = bigDecimal2.toString();
            supervisorPayRecord.setIsArrival(arrivalMoney+"%");
            supervisorPayRecordService.updateByPrimaryKey(supervisorPayRecord);
        } catch (MyException e) {
            e.printStackTrace();
            json.setFlag(false);
            json.setMsg("操作失败!!!"+e.getMessage());
            return json;
        }
        json.setFlag(true);
        json.setMsg("操作成功");
        return json;
    }


}
